SQL join | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

SQL join

Table projects id - pk, client_id - fk, title, url, description.. Table clients client_id - pk, name, url, Table images image_id - pk, project_id - fk, url, title I need to get all matching images from images with the same project id I came up with something that doesn't return all images, only the first match

28th Aug 2020, 4:22 AM
Akib
Akib - avatar
8 Answers
+ 2
Are there multiple images for a single project? you said "images with same project Id". If you only want the image (url) then I don't see why you are selecting projects.title and clients.name. Or did I misunderstood something?
28th Aug 2020, 8:17 AM
Ipang
+ 1
What query did you used?
28th Aug 2020, 4:50 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
Images doesn't have client_id
28th Aug 2020, 8:14 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
SELECT projects.title, clients.name, images.url FROM projects JOIN clients ON clients.client_id = projects.client_id JOIN images ON images.project_id = projects.id;
28th Aug 2020, 8:10 AM
Akib
Akib - avatar
0
Yeah, sorry about that, fixed it.
28th Aug 2020, 8:15 AM
Akib
Akib - avatar
0
I want all the properties from 3 tables at the same time.
28th Aug 2020, 8:18 AM
Akib
Akib - avatar
0
But your query is fine, if you want to get images for all projects
28th Aug 2020, 9:06 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
28th Aug 2020, 3:08 PM
🎯SS🎯
🎯SS🎯 - avatar