Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to order by another table column

I have 2 tables

1) movie

|id(pk),name|
============
|256    sdsd| 
|524    jmjm|
|122    dfdf|
|525    erer|
|952    tyyt|
|600    yunt|

2) favorites

|fid(pk),movie_id,uid   |
=========================
|1       256      454668|
|2       524      545656|
|3       122      454668|
|4       525      454668|
|5       952      454668|
|6       256      545656|
|7       625      454668|
|8       600      454668|

1st tables id and 2nd tables movie_id are same items...

My problem is.. first I want to get movie_id where uid = 454668 then using that movie_id(s) I want to list name where 'id' = 'movie_ids (list we got from last query) from first table but order by second tables fid...

How I can go???

I am not good at inner and joins

like image 708
user1753971 Avatar asked Dec 10 '25 14:12

user1753971


1 Answers

You can use INNER JOIN for that.

SELECT Name 
FROM movie m JOIN favorites f 
ON m.id = f.movie_id
WHERE f.uid = 454668 
ORDER BY f.fid

See this SQLFiddle

like image 74
Himanshu Jansari Avatar answered Dec 13 '25 08:12

Himanshu Jansari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!