View Single Post
  #5 (permalink)  
Old 01-15-09, 07:35
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,002
Why do you have to do two searches?

All friends of A
Code:
SELECT a.name As [user]
     , b.name As [friend]
FROM   users a
 INNER
  JOIN (
        SELECT user_id As [f1]
             , friend_user_id As [f2]
        FROM   friends
        UNION ALL
        SELECT friend_user_id As [f1]
             , user_id As [f2]
        FROM   friends
       ) As [f]
    ON a.user_id = f.f1
 INNER
  JOIN users b
    ON f.f2 = b.user_id
WHERE  a.name = 'A'
There's undoubtebly betteer ways, but i just knocked this up quickly to illustrate.
__________________
George
Twitter | Blog
Reply With Quote