Quote:
Originally Posted by sfdigital
SELECT movie_name
FROM table1
JOIN table2 USING (movie_id)
WHERE movie_genre = 'some_genre'
This is the example to get data from two tables
|
That is *ONE* example. It uses non-standard SQL but is allowable in MySQL.
There are so many ways you might want to get data from two tables that it's hard to pin it down to one example.
For example, suppose you wanted a list of all movie_genre's with a sub-list of the movies associated with that genre. And you want a genre to show even if there is currenly no movie in that genre.
Code:
SELECT t1.movie_genre, t2.movie_name
FROM table1 AS t1 LEFT JOIN table2 AS t2
ON t1.movie_id = t2.movie_id
ORDER BY t1.movie_genre, t2.movie_name
And there are many other possible choices.