开发者

How to use JOIN for my query?

I have two tables.

One contains:

id, album name, description, etc...

Another contains:

id, album id, photo

I want to get album details and its photos through album id?

How can I a开发者_运维百科chieve this?

Can I use left join?


Assuming your tables are called Albums and Photos:

SELECT Albums.*, Photos.Photo
FROM Albums
LEFT JOIN Photos
ON Albums.id=Photos.album_id
WHERE Albums.id=42


select a.id, a.album_name ..., b.photo 
from albums a 
left join OtherTable b on a.id = b.album_id


SELECT * 
FROM album a JOIN photo p
ON a.id=p.album_id 
WHERE a.id= 11
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜