views:

32

answers:

2

Hello,

I'm trying to get data from two MySQL tables, but having problems.

Usually, I'd use join to get data from two those tables depending on data, but this time I cannot, I think.

Here's situation: I'm having tables photos and photos_albums.

photos ID ALBUM FILENAME
photos_albums ID TITLE NAME

I need to get all albums and photo if exist in photos table. When I use join query will return albums only if photo with specific album id exists.

How to resolve? Any suggestions? Any help appreciated.

Regards, Tom

+1  A: 

Probalby you are using INNER JOIN (or just JOIN, which is the same), this way you are given the rows that have data in both tables. Try so select from albums and LEFT JOIN with photos table.

Draco Ater
No comments please. Of course LEFT JOIN works correctly, I'm just too tired. Thanks for help!
Tom
+1  A: 

When joining two tables, you can specify the join type in order to return records that have matching criteria (in the ON clause), or all records from one of the join tables, regardless if it has a corresponding row in the other table. This can be achieved by using a LEFT OUTER JOIN.

Oded