4
I’m having a lot of doubts about Mysql when I have to use INNER JOIN
to retrieve data from other tables.
I have 3 tables:
MEDIA
id, user_id, title, Description
COMMENTS
id, user_id, media_id, comment
MEDIA_LIKES
id, user_id, media_id
The MEDIA table is the main one, it contains the id do post
and id do usuário
, then I have the comments table where you have the comments posted in certain posts and then the like
also given in these posts.
My big doubt is like through a Query in Mysql I can get the table data MEDIA
, the amount of comments and likes
data for given media_id
?
friend, I tried like this <br><br> "SELECT Count(b.id) as Likes, Count(c.id) as comments, a.* from media a, media_likes b, comments c WHERE a.id=214;" <br><br> ?
– Patrique
it was badly I had pasted but it was not everything , already I answered the query
– Jasar Orion
Jasar, it worked now bro, thank you so much for your help gave straight :D thank you very much, would never be able to mount a query so >( thanks even for the help
– Patrique
Dude, honestly, I got to a point where I didn’t know how to assemble the queries, my breaking point was when I started to understand how it works, the logic itself. Try to draw the query that helps. you draw the tables and one meets the other this he the basic query you do after is only for the rest of the conditions necessary to pull the info q vc need.
– Jasar Orion
I will try to follow this logic, but still not being able to understand how it works rs, one last doubt I saw now, not being able to recover the result of the number of comments, what can be happening, my query with your help was like "SELECT Count(b.id) as Likes, Count(c.id) as comments, a.* from media a, media_likes b, comments c Where a.id='214' and a.id=b. media_id and a.id=c.media_id;"
– Patrique
seems right, has comments with media_id 214?
– Jasar Orion
has 1, more ta appearing 3 like media_likes, ta repeating, if I put 1 more in media_likes it repeats in the call I make from Count to comment
– Patrique
Can you give a copy of this db for me to test ? then I mount the query and t step
– Jasar Orion
below is the download file http://www.filedropper.com/teste_4 Thank you very much. Thank you :D
– Patrique
solved ta edited up there the working query
– Jasar Orion
Tu é sinistro mano! thanks a lot, thanks a lot for your help, you saved me! thanks a lot, thanks a lot :D
– Patrique
rsss q that I need he only put here. c I did not have for help others will. as you tbm am learning. good luck there
– Jasar Orion
tmj Leke, Rigadão and Valeu!
– Patrique