IN CLAUSE

Hello, I think I'm getting something in SQL SERVER that is none sence for me at least...

Example:

SELECT * FROM A

WHERE A.ID IN (SELECT B.ID FROM B WHERE A.NAME='ABC')

This query is returning DATA and It works... in SQL SERVER 2000

Can I invoke an external table in a subquery that is using IN clause

This is not possible in many other DBMS... I don't know if this a BUG (offcourse It's possible with an EXISTS clause but It should be possible with IN clause)




Answer this question

IN CLAUSE

  • bw12117

    If SQL Server lets you do this then fair enough. You don't have to use this feature if you don't want!

    Chris



  • jeffli

    You probably wouldn't feel it was such an issue if you had:

    where exists (select * from B where b.id = a.id)

    --and yet this works in exactly the same way, in every DBMS I can think of.

    Rob


  • MehrdadDotNetOK

    Hello, I know the number of columns selected in the inside query has to match with the outside query, the problem here is that It shouldn't be possible to invoke table A from the inside query (Query that is after IN clause), It sould be only possible to invoke columns from outside table B.

    Aren't I right



  • adarsh.mathur

    It's called a 'Corelated Sub-Query', since the inner query is related to data in the outer query.

  • Charlie Calvert MSFT

    Yes.

    Keep in mind that the IN keyword seeks to evaluate a list following the [IN]. As long as the sub-query provides a proper list, then is is legitimate. Add a second column to the sub-select and it will fail because it is then an improper list to evaluate.



  • plneo

    Jortiz:

    I am not sure that I get your question, but if what you are asking is if the syntax you presented is officially support in MS SQL Server the short answer to your question is, "Yes".


  • .NET Developer

    Thanks for picking me up on that, Arnie; a very good point.
  • IN CLAUSE