Created
March 30, 2012 21:22
-
-
Save santiagobasulto/2255231 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SELECT u.id,u.first_name FROM auth_user u | |
JOIN ( | |
SELECT IF(user1 = 1,Null,user1) res1 ,IF(user2 = 1,Null,user2) res2 | |
FROM auth_user u JOIN friendship f | |
ON (u.id = f.user1 OR u.id=f.user2) | |
WHERE | |
u.id = 1 | |
) t ON (u.id=res1 OR u.id=res2) | |
-- Dustin QUery | |
select * from auth_user u | |
left join ( | |
select user1_id as friend_id from profile_friendship where user2_id = 1 and status = 'Accepted' | |
union | |
select user2_id as friend_id from profile_friendship where user1_id = 1 and status = 'Accepted' | |
) as f on f.friend_id = u.id | |
where u.first_name like 'd%' | |
order by f.friend_id > -1 desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment