[英]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
?我想通过
album id
获取相册详细信息及其照片?
How can I achieve this?我怎样才能做到这一点?
Can I use left join?我可以使用左连接吗?
Assuming your tables are called Albums
and Photos
:假设您的表格被称为
Albums
和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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.