Hello,This query, which search through a "friends" table for a social networking site, returns way too many results (about 50 rows when there is only 1 user that matches the criteria). The reason why I have to do is a UNION is because the "Friends" table looks like this:FriendID (int)UserID (int)A "friend ID" can be in either row, so if your userid is 61 then if FriendID = 61 and UserId = 51 then 51 is your friend, or if UserId = 51 and FriendID = 101 then 101 is your friend. Make sense?Here is the query:SELECT A.userid , A.FriendId , A.SortOrder , A.Status , A.dateAdded , B.UserName , B.Quote FROM Wisetopic_friend AINNER JOIN WiseTopic_User B ON A.FriendId = B.UserId WHERE B.userid=@userid AND B.displayname like '%' + @searchstring + '%' OR B.username like '%' + @searchstring + '%' OR B.fname like '%' + @searchstring + '%' OR B.lname like '%' + @searchstring + '%'UNIONSELECT A.FriendId AS UserId, A.UserId AS FriendId, A.SortOrder, A.Status, A.dateAdded, B.UserName, B.QuoteFROM Wisetopic_friend AINNER JOIN WiseTopic_User B ON A.UserId = B.UserIdWHERE B.userid=@userid AND B.displayname like '%' + @searchstring + '%' OR B.username like '%' + @searchstring + '%' OR B.fname like '%' + @searchstring + '%' OR B.lname like '%' + @searchstring + '%'GO
I think its a very simple problem, maybe my LIKE statements are too greedy?Thank you very much!