mysql - How to check for multiple columns in a subquery? -


i have couple of tables in mysql representing undirected graph. users table has user_id (and other stuff don't need right now), while links table has user_id_1 , user_id_2 (and other data need come along ride). i'm trying links between given user's neighbors (including himself). question, basically, is: how do this? managed of user's neighbors, plus himself, following unfortunate query:

select u.* users u join links l on u.user_id = l.user_id_1 l.user_id_2 = @arg union select u.* users u join links l on u.user_id = l.user_id_2 l.user_id_1 = @arg union select * users user_id = @arg 

now want select links both user_id_1 , user_id_2 appear in above query. is there way without performing query twice? because (although haven't profiled it) have sneaking suspicion above query pretty non-performant. secondary question, there better way subquery?

edit: having been asked sample data , output, here goes. give links table here. promise of these users exist in users table, don't need worry joins failing or that. think question should answerable without joining users @ all.

link_id  user_id_1  user_id_2 1                 b 2        c          b 3        c          4        d          c 5        c          e 6        d          e 7                 d 8        f          

if query a, users query above should return except e, isn't neighbor of (all others are). query i'm looking needs return of links in table except 5 , 6, involve e. in particular needs return 2 , 4, links directly involving a.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -