Reputation: 15
I am trying to join 3 tables. I would like to each project one time if it has a post with media in that post.
SELECT *
FROM `database`.project join
post
on post.project_id = post.id join
media
on media.post_id = post.id
What i currently get as result
Example
I want to code to return one instance of
Floaty
HeadPhones
Fasion + Technologie
so that it doesn't return multiple projects
Any help would be much appricated
Upvotes: 0
Views: 49
Reputation: 135
you can use distinct: select distinct project.id. https://www.w3schools.com/sql/sql_distinct.asp
Or you can use group by: group by project.id, project.name... https://www.w3schools.com/sql/sql_groupby.asp
Both of then needs to put all the fields results on the query
Upvotes: 0
Reputation: 2686
SELECT distinct name
FROM database.project join
post
on post.project_id = post.id join
media
on media.post_id = post.id
Upvotes: 1