Created
July 26, 2011 02:48
-
-
Save rickosborne/1105838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE friends ( | |
person1 INT NOT NULL, | |
person2 INT NOT NULL, | |
PRIMARY KEY (person1, person2) | |
); | |
SELECT p.* | |
FROM people AS p | |
INNER JOIN ( | |
SELECT person1 AS friend | |
FROM friends | |
WHERE (person2 = ?) | |
UNION ALL | |
SELECT person2 AS friend | |
FROM friends | |
WHERE (person1 = ?) | |
) AS f ON (p.personID = f.friend); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment