开发者

Query to get data from two tables

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开发者_如何学运维


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜