Click here to Skip to main content
15,909,030 members
Home / Discussions / Database
   

Database

 
QuestionIIS Webhits via ADO.NET? Pin
harryteck18-Mar-05 13:39
harryteck18-Mar-05 13:39 
GeneralINNER JOIN Pin
HahnTech18-Mar-05 9:00
HahnTech18-Mar-05 9:00 
GeneralRe: INNER JOIN Pin
HahnTech18-Mar-05 10:22
HahnTech18-Mar-05 10:22 
QuestionCan someone give me an advise for my application's database Pin
Blue_Skye18-Mar-05 6:31
Blue_Skye18-Mar-05 6:31 
QuestionWhich is better on webservice? Pin
WDI18-Mar-05 0:27
WDI18-Mar-05 0:27 
AnswerRe: Which is better on webservice? Pin
Hesham Amin18-Mar-05 2:13
Hesham Amin18-Mar-05 2:13 
Generaland - or statement Pin
WDI18-Mar-05 0:20
WDI18-Mar-05 0:20 
GeneralRe: and - or statement Pin
Colin Angus Mackay18-Mar-05 1:58
Colin Angus Mackay18-Mar-05 1:58 
That is the correct result for the query you supplied. IN(...) means that the value can be any one of the values in the list.

First an explanation of why you are seeing the results you get.

Breaking this query down into smaller parts:

SELECT * FROM VIEW WHERE TypeID IN (1,3) will return
__________________________
ID  Name   TypeID 
__________________________
1 | John  | 1 
1 | John  | 3 
2 | Mary  | 3 
3 | Betty | 1 
3 | Betty | 3 
__________________________
SELECT ID FROM... will return
__________________________
ID
__________________________

1
1
2
3
3
__________________________
And so SELECT DISTINCT ID FROM... will return
__________________________
ID
__________________________

1
2
3
__________________________



So, if you only want to get the IDs where there is a TypeID of 1 and 3.


The SQL you are looking for is:
SELECT DISTINCT ID FROM [VIEW]
WHERE TypeID IN (1,3)
AND ID NOT IN (SELECT ID FROM [VIEW]
WHERE TypeID NOT IN (1,3)) 


What this does is get a list of the IDs as you did before, but it also subtracts the IDs that have values NOT IN the list of TypeIDs that you specify
SELECT ID FROM [VIEW]
WHERE TypeID NOT IN (1,3)

returns a list of IDs that you are not interested in.

Does this help?


My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More


GeneralRe: and - or statement Pin
WDI25-Mar-05 6:46
WDI25-Mar-05 6:46 
GeneralRe: and - or statement Pin
Colin Angus Mackay25-Mar-05 11:18
Colin Angus Mackay25-Mar-05 11:18 
GeneralRe: and - or statement Pin
Michael Potter18-Mar-05 6:01
Michael Potter18-Mar-05 6:01 
GeneralRe: and - or statement Pin
Michael Potter18-Mar-05 6:13
Michael Potter18-Mar-05 6:13 
GeneralRe: and - or statement Pin
WDI18-Mar-05 9:31
WDI18-Mar-05 9:31 
GeneralRe: and - or statement Pin
Michael Potter18-Mar-05 10:04
Michael Potter18-Mar-05 10:04 
Questionhow to call for update in two different databases? Pin
mijan17-Mar-05 19:47
mijan17-Mar-05 19:47 
AnswerRe: how to call for update in two different databases? Pin
Anonymous20-Mar-05 21:54
Anonymous20-Mar-05 21:54 
GeneralPage numbers Pin
Sebastien Lachance17-Mar-05 8:02
Sebastien Lachance17-Mar-05 8:02 
GeneralRe: Page numbers Pin
Michael Potter17-Mar-05 9:54
Michael Potter17-Mar-05 9:54 
Questionhow to add oledb connection in module by writing code Pin
sumit2117-Mar-05 7:42
sumit2117-Mar-05 7:42 
AnswerRe: how to add oledb connection in module by writing code Pin
rwestgraham20-Mar-05 12:31
rwestgraham20-Mar-05 12:31 
GeneralJoin Problem Pin
Brian Van Beek17-Mar-05 6:25
Brian Van Beek17-Mar-05 6:25 
GeneralRe: Oops. More Info Pin
Brian Van Beek17-Mar-05 6:26
Brian Van Beek17-Mar-05 6:26 
GeneralRe: Join Problem Pin
BammBamm17-Mar-05 8:08
BammBamm17-Mar-05 8:08 
GeneralSql Backup and Restore Pin
| Muhammad Waqas Butt |16-Mar-05 22:12
professional| Muhammad Waqas Butt |16-Mar-05 22:12 
GeneralRe: Sql Backup and Restore Pin
Colin Angus Mackay17-Mar-05 6:30
Colin Angus Mackay17-Mar-05 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.