Re: Need SQL Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "J. Kevin C. Burton" <KBurton@xxxxxxxxxxxxxxxx>

> 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...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux