MySQL LEFT JOIN不起作用

时间:2014-05-04 02:07:59

标签: mysql sql join

我有两个MySQL表:

tbsongs:

enter image description here

tbalbums:

enter image description here

我正在尝试从tbsongs进行查询以添加来自tbalbums的字段,但是我收到错误,并且找不到错误的位置。

您可以在此查询:

 $rs = mysql_query("SELECT * FROM tbsongs where tbsongs.index='$id' 
LEFT JOIN tbalbums AS nombreAlbum ON tbsongs.album = tbalbums.idAlbums ORDER BY titulo asc");

1 个答案:

答案 0 :(得分:2)

WHERE在任何JOIN ORDER BY之后

SELECT 
   n.*,m.* 
FROM tbsongs n 
LEFT JOIN tbalbums m ON n.album = m.idAlbums
WHERE n.index='$id'   
ORDER BY n.titulo ASC