Re: Need SQL Help

From: Date: Thu, 12 Feb 2004 18:52:55 +0000
Subject: Re: Need SQL Help
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-32921@lists.php.net to get a copy of this message
From: "J. Kevin C. Burton" <KBurton@SimplicityCS.com> > I have a SQL statement that looks like this: > "SELECT EMPLOYEENAME,SUPERVISORID WHERE EMPLOYEEID='$employeeid'" > > what I want to do is lookup the supervisor's name in the same SQL > statement. If not, I would have to use an function, and if I have a 100 > employee's in the list, that takes an enormous amount of time if I have > to load that function every row. > > Is there a way to do it all in the same 1 SQL statement? Is this a Parent-Child type relationship, where the supervisor ID is actually just another employee ID in the same table? If so, you could do it like this: SELECT t1.employeename, t1.supervisorid, t2.employeename as supervisorname FROM employees t1, employees t2 WHERE t1.supervisorid = t2.employeeid NAD employeeid = '$employeeid' If that's not your table structure, then you'll have to tell us what it is. ---John Holmes...

« previous php.db (#32921) next »