June 4, 2010 at 7:38 am
I would like to use thee result set in in function ex :
Select * from table1 where column1 in (select column2 from table2)
is it the right way of using it ?
June 4, 2010 at 8:04 am
June 4, 2010 at 8:11 am
Well i tried but its showing up the data for only one value instead of showing data for all the values(from second query )?
June 4, 2010 at 8:22 am
What you wrote should work.
Note that you can re-write this query as a JOIN:
SELECT t1.*
FROM Table1 t1
JOIN Table2 t2
ON t1.Column1 = t2.Column2
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 4, 2010 at 8:41 am
Are you saying you want to see all columns from Table2 as well? Then Wayne's example only needs a tiny change:
SELECT t1.*, t2.*
FROM Table1 t1
JOIN Table2 t2
ON t1.Column1 = t2.Column2
June 4, 2010 at 10:24 am
Thanks Guys
June 6, 2010 at 7:59 am
WayneS (6/4/2010)
What you wrote should work.Note that you can re-write this query as a JOIN:
SELECT t1.*
FROM Table1 t1
JOIN Table2 t2
ON t1.Column1 = t2.Column2
This is not the same as the IN query. It will potentially procedure a different result if a value appears in multipl rows in table2.
June 7, 2010 at 5:40 am
True Nils, but since the OP's question wasn't exactly clear (and he didn't get any more specific later), both Wayne and I just took a stab at it.
June 7, 2010 at 5:44 am
I agree, the OP was unclear. I was not criticizing your answer, just pointing out that the two queries would return different results 🙂
June 7, 2010 at 11:28 am
Jan Van der Eecken (6/4/2010)
Are you saying you want to see all columns from Table2 as well? Then Wayne's example only needs a tiny change:
SELECT t1.*, t2.*
FROM Table1 t1
JOIN Table2 t2
ON t1.Column1 = t2.Column2
Good call Jan!
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply