songs_albums.cat = songs_singers.id
CAT = ID
我如何才能加入所有专辑歌手?
$qr=mysql_query("
select songs_albums.*
, songs_singers.name as singer_name
, songs_singers.id singer_id
, songs_singers.page_name singer_page_name
, songs_singers.img singer_img
from songs_albums
, songs_singers
where songs_singers.active=1
and songs_albums.cat=songs_singers.id
limit 8
") ;
答案 0 :(得分:1)
如果我们假设song_singers.Id与song_albums.cat相同,那么你已经是。您只是使用ANSI 89标准而不是ANSI 92标准。
一些提示:
ANSI-89标准:
SELECT SA.*
, ss.name as singer_name
, ss.id as singer_id
, ss.page_name as singer_page_name
, ss.img as singer_img
FROM songs_albums SA
, songs_singers SS
WHERE ss.active=1
and sa.cat=ss.id
ORDER BY sa.ID, SS.ID
LIMIT 8
使用内连接的ANSI-92标准。
SELECT SA.*
, ss.name as singer_name
, ss.id as singer_id
, ss.page_name as singer_page_name
, ss.img as singer_img
FROM songs_albums SA
INNER JOIN song_singers SS
on sa.cat=ss.id
WHERE ss.active=1
ORDER BY sa.ID, SS.ID
LIMIT 8
答案 1 :(得分:0)
你可以将专辑ID分配给特定的歌手。现在让所有专辑的所有歌手离开加入查询都是那样的
$sql = "select sa.*,s.id,s.name as singer_name from song_singers as s left join songs_album as sa ON sa.id=s.album_id where s.active=1";