我的数据库中有4个表,我需要将四个表连接在一起,但不能再连接两个表
$query = '
SELECT
movie_title,genre_label,movie_year,director_name,movie_genre,movie_director,movie_actor
FROM
general LEFT JOIN genre ON movie_genre = genre_id AND
general LEFT JOIN movie_directors ON movie_director = director_id
WHERE
general.movie_genre = genre.genre_id AND
general.movie_director = movie_directors.director_id
ORDER BY
movie_year';
我的浏览器显示此错误:
Unknown column 'general' in 'on clause'
请帮助我,谢谢
最佳答案
您不必在联接之间插入AND并重复查询的表。
您的查询应如下所示:
$query = '
SELECT
movie_title,genre_label,movie_year,director_name,movie_genre,movie_director,movie_actor
FROM
general
LEFT JOIN genre ON movie_genre = genre_id
LEFT JOIN movie_directors ON movie_director = director_id
ORDER BY
movie_year';
关于php - mysql对一个查询进行多次联接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29417645/