我一直试图解决这个问题很长一段时间,我放弃了。 我从一张桌子上获取信息,没问题。 但我需要根据另一个表中的信息排除一些结果。
querylist
id | artist | title
1 | Kelly Clarkson | Catch My Breath
2 | Nicki Minaj | Va Va Voom
3 | Jingle | Jingle100
songlist
id | artist | title | songtype
1 | Kelly Clarkson | Catch My Breath | S
2 | Nicki Minaj | Va Va Voom | S
3 | Jingle | Jingle100 | I
当我从querylist表中获取结果时,我想从歌曲列表中排除所有没有歌曲类型S的歌曲。
我有这个,我如何才能获得歌曲S的歌曲?
$result = mysql_query("SELECT * FROM queuelist q LEFT JOIN requestlist r ON q.requestid = r.id LEFT JOIN songlist s ON q.songid = s.id ORDER BY q.sortID ASC LIMIT 5 ",$dbcon);
echo "<table>\n";
if ($myrow = mysql_fetch_array($result)){
do{
$artist = $myrow["artist"];
$title = $myrow["title"];
echo "<tr><td>$artist - $title</td>";
echo "</tr>\n";
}while($myrow = mysql_fetch_array($result));
}
echo "</table>";
答案 0 :(得分:2)
要明确:添加:WHERE s.songtype ='S'
SELECT * FROM queuelist q
LEFT JOIN requestlist r ON q.requestid = r.id
LEFT JOIN songlist s ON q.songid = s.id
WHERE s.songtype='S'
ORDER BY q.sortID ASC LIMIT 5