Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Ascertaining a subset of a select query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-24 : 10:19:34
Alistair writes "Hello - I have a question on joins that I havn't been able to find answered anywhere.

example: Imagine I two tables with similar stuff in:


YourTable MyTable
------- -------
ID Code ID Code
----- ------
1 A
2 B 2 B
3 C 3 C
4 D
5 E
6 F
7 G

..and have the query:

SELECT Code FROM YourTable WHERE *ALL* IN (SELECT Code FROM MyTable WHERE ID >= 2 AND <=4)


(The *ALL* is what I want to write but can't!)

What is different is that I don't want any results returned unless ALL the Codes in YourTable are to be found in MyTable.

The above case would correctly return B anc C. But if YourTable started with


ID Code
-----
2 B
3 C
8 H

... you wouldn't get any results.

In other words how do I SELECT the Codes in YourTable which appear in MyTable only when ALL the Codes appear in the MyTable Query? It can be done with Counts and Variables and things, but I wondered if there was a simpler way?

(I've tried to simplify this problem as much as possible, but if not do let me know and I'll rephrase it!)

Alistair Potts
alistair@screenpages.com"
   

- Advertisement -