开发者

How to use JOIN for my query?

开发者 https://www.devze.com 2023-03-12 00:18 出处:网络
I have two tables. One contains: id, album name, description, etc... Another contains: id, album id, photo

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

精彩评论

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