Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL join two tables where IDs match

Tags:

sql

join

I have two tables in my database.

Movies table:

+----------------------------------------
| ID | title                | timestamp |
+----------------------------------------
| 1  | The host             | time      |
| 2  | Fight Club           | time      |
| 4  | 21                   | time      |
----------------------------------------+

Movie_Links table:

+---------------------------------------+
| ID | link                 | movie_id  |
+---------------------------------------+
| 1  | some link            | 1         |
| 2  | some link            | 1         |
| 3  | some link            | 1         |
+---------------------------------------+

At the moment I am only selecting the rows from the Movies table where the title is like for example:

SELECT * FROM `Movies` 
WHERE `title` LIKE '%The Host%' 
ORDER BY `timestamp` DESC DESC LIMIT 30

But what I want to do is the same query as above but join Movie_Links table where movie_id equals Movies table's ID and get all links that have a Movie_id equal to 1.

like image 825
Ashley Williams Avatar asked Mar 10 '26 01:03

Ashley Williams


1 Answers

SQL join two tables With IDs match

SELECT *
FROM Movies 
LEFT JOIN Movie_Links 
ON Movies.ID = Movie_Links.movie_id;
like image 192
Tufayal Hossin Avatar answered Mar 11 '26 15:03

Tufayal Hossin



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!