0

the DB looks like this, and I need a query to get each stat with the idstat, the user downloader, and the user creator. Without adding a line "user_creator" in the stat table. I should be able to get the user creator with stat.contentidcontent > content.iduser but I can't reach it, I always get the iduser_downloader in the iduser_creator column.

Thanks!

enter image description here

1
  • Just join the three tables. Please show us your query and we'll tell you what's wrong about it. If you want both users, you'll have to join the user table twice. Commented Aug 31, 2020 at 8:35

1 Answer 1

2

You must join 2 copies of user to get the downloader and the creator:

select s.idstad,
       ud.iduser downloader_id, ud.name downloader_name,
       uc.iduser creator_id, uc.name creator_name
from stat s
inner join user ud on ud.iduser = s.user_iduserdownloader
inner join content c on c.idcontent = s.content_idcontent
inner join user uc on uc.iduser = c.user_iduser_creator
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works. There a just a missing coma after the first line ;) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.