RE: [PHP] SQL : left join from multiple tables

From: Date: Tue, 24 Sep 2002 11:39:29 +0000
Subject: RE: [PHP] SQL : left join from multiple tables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117399@lists.php.net to get a copy of this message
[snip] [snip] "select a.name, b.department, c.position from emp a left join dept b on a.staffno = b.staffno left join position c on a.staffno = c.staffno where staffno = $staffno"; I know the statement above is totally wrong. I'm just hoping u guys can understand what i'm trying to achieve from it. [/snip] All you have to change to make this right is change the ON statement after 'left join position c' to 'on b.staffno = c.staffno'. Remember that you are moving from left to right in the join, so your ON must also move from left to right. [/snip] I also just realized that your where statement may be too ambiguous, so change it (again think from left to right) to 'where a.staffno = $staffno'. Since a.staffno should match b.staffno should match c.staffno. HTH! Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#117399) next »