Sri Sri - 6 months ago 9
SQL Question

SQL Server : Subquery returned more than 1 value

i have two tables

User Table : Column Names - (pk)UserID, Username, Firstname, Lastname....

UserID | Username | FirstName | Lastname

1001       KiranReddy     Kiran          Reddy
1002       Arvind              Arvind         Kumar

1003       Arun                 Arrun         Swamy

1004       Ramesh           Ramesh    Naidu

1005       Ramesh           Ramesh    Naidu

1006       Ajay1233           Ajay          Sharma


Friend Table: Column Name - (fk)UserID1, (fk)UserID2, friendstatus,.....

UserID1 | UserID2

1001          1002

1001          1003

1001          1004

1001          1005

1001          1006



For Example : - I'm the UserID1 = '1001'

Here my requirement is i want to get those username whose UserID2 username start with 'A%'

i hope my question is clear

Answer
Select friend.UserID2 from User
left join Friend on friend.userid1 = user.userid
Where user.username like '%A' and friend.UserID1 ='1001'
Comments