w3father
w3father

Reputation: 569

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 achieve this?

Can I use left join?

Upvotes: 0

Views: 55

Answers (3)

David Tang
David Tang

Reputation: 93664

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

Upvotes: 2

Shakti Singh
Shakti Singh

Reputation: 86346

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

Upvotes: 1

Simon Elliston Ball
Simon Elliston Ball

Reputation: 4455

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

Upvotes: 1

Related Questions