Reputation: 26
songs_albums.cat = songs_singers.id
CAT = ID
How i can do JOIN to get all albums singers ?
$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
") ;
Upvotes: 0
Views: 54
Reputation: 35323
You already are if we assume the song_singers.Id is the same as the song_albums.cat. You're just using the ANSI 89 standard instead of the ANSI 92 standard.
A few hints:
.
ANSI-89 standard:
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 Standard using inner join.
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
Upvotes: 1
Reputation: 167
you can assign album id to particular singer.so now to get all singers of all albums left join query is like that
$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";
Upvotes: 0