question

leo2015 avatar image
leo2015 asked

List of multiple records referring another table

I want to get a list of all the records for below query, at the moment there are hundreds of record exist for this query but as this query can only return one record (even I will have to add "Top 1"), I cannot use it. Can someone help me to change this query so that I can get all the records from Table T1 for the condition, below is my query: select * from table T1 where COLUMN C1 = (select COLUMN C2 from Table T2 where COLUMN C3 = Value)
sql-server-2008sql-server-2005
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

seanlange avatar image seanlange commented ·
As posted there is no chance anybody can help you. There simple isn't enough information for anything more than a guess. It seems like you could change this to a join but it is impossible to tell for sure. This would be a great place to start for getting an answer. http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/
0 Likes 0 ·
erlokeshsharma08 avatar image
erlokeshsharma08 answered
Or you could use 'in' clause to get all the records:- select * from table T1 where COLUMN C1 in (select COLUMN C2 from Table T2 where COLUMN C3 = Value)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tom Staab avatar image
Tom Staab answered
Assuming a variable @value is of the right data type and holds the value you want for your criteria, I believe the following should work for you: SELECT t1.* FROM table1 t1 INNER JOIN table2 t2 ON t2.column2 = t1.column1 WHERE t2.column3 = @value ;
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.