I have a table like this (say, friends):

|_name1_|_name2_|
| james | sarah |
| bob   | james |
| james | dave  |

I want all james' friends. It will need to include 'bob' as well but I can not figure out what the query will need to be like sine james is on both fields. Thanks.

Select * from friends where name1='james' or name2='james';

OR

Select name2 from friends where name1='james'
union
select name1 from friends where name2='james';

This second one is most likely what you want as it gives a list of just the friends' name.

Thanks for the reply :) I was wondering if there was a solution that doesn't use UNION.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.