i've two tables,

a) albums

alt text

b)pictures

alt text

i'm while using following query to choose the albums.id, albums.cover_picture_id, pictures.url where albums.cover_picture_id = pictures.id, i wish to carry out the following

select all the values from albums, however it also needs to fetch the images.web address with regards to albums.cover_picture_id

with the objective i'm while using following Choose STATEMENT

SELECT 
albums.id,
albums.cover_picture_id,
pictures.url
FROM albums 
JOIN pictures 
ON 
(
albums.cover_picture_id = pictures.id
)

it really works fine but i've got a problem here, the table entity albums.cover_picture_id could have the worthiness which doesn't appear in pictures.id so it won't fetch the worthiness whether it finds , i may wish to fetch all of the albums in the albums table even when it finds . how do you add the clause within the choose statement.

thanks

Try altering your JOIN to LEFT JOIN since you need to include all records from albums even when there's no matching record in pictures:

SELECT 
albums.id,
albums.cover_picture_id,
pictures.url
FROM albums 
LEFT JOIN pictures 
ON 
(
  albums.cover_picture_id = pictures.id
)

use [cde] such as this:

LEFT JOIN

Excerpt from Wikipedia:

The effect of a left outer join (or just left join) for table A and B always consists of all records from the "left" table (A), even when the join-condition doesn't find any matching record within the "right" table (B). Which means that when the ON clause matches (zero) records in B, the join will still return a row within the result—but with NULL in every column from B. Which means that a left outer join returns all of the values in the left table, plus matched up values in the right table (or NULL just in case of no matching join predicate). When the right table returns one row and also the left table returns several matching row for this, the values within the right table is going to be repeated for every distinct row around the left table.