- Employee name [primary key]
- Employee data (address, etc.)
- Chief [foreign key to this table]
How could I construct a SELECT statement to get all employees that, for example, have the same address as their boss?
Name:
Anonymous2005-09-02 5:06
SELECT * FROM employees AS e1 JOIN employees AS e2 ON e1.chief = e2.name WHERE e1.address = e2.address
Or something along those lines, I haven't done SQL in a while.
I'm going to assume this table was made up as an example and ignore your choice of primary key. :P
Name:
Anonymous2005-09-02 5:10
Oh, adding to that, that isn't really recursion. Recursion would be if you wanted to say, output a tree structure - this is possible with a recursive nested statement thingy, I've seen it done before, but I can't remember how to do it.
Name:
Anonymous2005-09-18 23:31
if sql queries were recursive they wouldn't halt.
Name:
Anonymous2009-02-21 8:06
niggers
Name:
Anonymous2009-02-21 12:17
>>4
alot of non standard sql language think they're so clever by including reptition and recursion tools in their SQL DBMS but if you think a loop is a good idea in an sql query you're probably doing it wrong