sql server 2008 - SQL Selecting One Entire column based on from parameters? -


this question has answer here:

i have table , need help:

friends:

  • my_e_mail (varchar) ,
  • friends_e_mail (varchar)

these sample values:

alester@pam.com carl@pam.com alester@pam.com greg@pam.com alester@pam.com jude@pam.com 

what need select either my_e_mail or friend_e_mail not match parameter plug in using ? in sql server 2008 using.

for example:

select friend_e_mail friends  friend_e_mail not in (?) 

what want show list of friends each person. example alester has 3 friends each of others people have 1 friend alester.

also cannot create table.

any appreciated.

maybe union need:

declare @email varchar(50) set @email = ?  select     friend_e_mail email         friends       my_e_mail = @email     , friend_e_mail <> @email union select      my_e_mail email      friends       friend_e_mail = @email     , my_e_mail <> @email 

this code return 3 rows alester@pam.com 1 row each of other three.

note union return distinct rows. if need keep duplicates, use union all. in addition, if know ahead of time results distinct, use union all, save performance cost comes distinct.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -