4
I have these 3 tables below: "users", "Friends" and "posts".
I want to take all my friends who are in the table of Friends and display their posts, taking the name of each and their image (which are in the table of users).
Imagine a news feed, where I have to show the posts.
I wanted to try to do so with JOINS, without using subselect(which was the way I found to do)
Thank you!
That’s easy to do, but what you’ve tried?
– Marco Souza
SELECT p.descr,p.dt_hr, (SELECT U1.name FROM users U1 WHERE U1.id = f.id_friend) AS name FROM Friends f JOIN users u ON u.id = f.id_user POSTS join p ON p.id_user = f.id_friend WHERE u.id = 1 ORDER BY p.dt_hr DESC
– Leonardo
The one I rode was the one above, but I need to return two fields of this subselect, and it only returns 1. In case, I need the name and image...
– Leonardo
and how hard it is to make another Join with it?
– Marco Souza
I’m not succeeding, could help?
– Leonardo
see if this is what you wanted.
– Marco Souza
That’s right, it’s because I was already making a Join at users, I didn’t think I needed to make one more, you know? But thanks man. Thank you very much!!
– Leonardo