Page 1 of 1

Multiple Joins (SQL)

Posted: Mon Nov 17, 2003 3:02 pm
by Cruzado_Mainfrm
How do you make multiple joins? i know how to make a join of two tables, for ex:

Code: Select all

<?php
$query = "SELECT l.lyricid,l.hits,t.titlename FROM lyrichits AS l LEFT JOIN titles AS t ON (l.lyricid=t.lyricid) ORDER BY hits DESC LIMIT 0,10";
?>
but i wanna make a join that resembles this

tables:
-<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> //visits to every lyric. fields: lyricid(relation),hits.
-titles //contains all the titles. fields: titleid,lyricid(relation),titlename,artistid(relation)
-artists //contains the name of the artists. fields: artistid(relation),artistname
-lyrics //table not used. fields: lyricid(relation),data

and the sql query has to return the top 10 lyrics with this data:
artistid,artistname,lyricid,titlename

and for this i need two joins instead of one, a thing that i don't know how to do, any help :D?

Posted: Mon Nov 17, 2003 3:08 pm
by Cruzado_Mainfrm
LOL, solved:

Code: Select all

<?php
$query = "SELECT l.lyricid,l.hits,t.titlename,a.artistname FROM lyrichits AS l LEFT JOIN titles AS t USING (lyricid) LEFT JOIN artists AS a USING(artistid) ORDER BY hits DESC LIMIT 0,10";
?>