Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

DB recursive relations question

Name: Anonymous 2005-09-02 4:35

Hi /prog, say I have a table with two columns:

- 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: Anonymous 2005-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: Anonymous 2005-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: Anonymous 2005-09-18 23:31

if sql queries were recursive they wouldn't halt.

Name: Anonymous 2009-02-21 8:06

niggers

Name: Anonymous 2009-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

Name: Anonymous 2009-02-21 17:46

>>6

Name: Anonymous 2009-02-23 23:11

Look at Oracle's hierarchical query feature.

Name: Anonymous 2009-03-06 5:40

Going to post HAX   MY ANUS try   to include some   relevant content to   go with it   Any good books   on MS Access.

Name: Anonymous 2009-03-06 11:35

Is thread is unscientific and ultimately destructive   usage of cat   Award form letter.

Name: Anonymous 2011-01-31 21:37

<-- check em dubz

Name: Anonymous 2011-02-03 6:31

Name: Anonymous 2013-07-30 18:08

Lain

Don't change these.
Name: Email:
Entire Thread Thread List