Click here to Skip to main content
15,898,371 members
Home / Discussions / Database
   

Database

 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 3:19
Jeff Martin24-Mar-05 3:19 
GeneralRe: Row ID after INSERT to database Pin
Abyss24-Mar-05 3:38
Abyss24-Mar-05 3:38 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 4:06
Jeff Martin24-Mar-05 4:06 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 3:15
Jeff Martin24-Mar-05 3:15 
GeneralRe: Row ID after INSERT to database Pin
Abyss24-Mar-05 3:45
Abyss24-Mar-05 3:45 
GeneralRe: Row ID after INSERT to database Pin
Jeff Martin24-Mar-05 4:08
Jeff Martin24-Mar-05 4:08 
QuestionColin Angus Mackay ???? Pin
WDI22-Mar-05 9:11
WDI22-Mar-05 9:11 
AnswerRe: Colin Angus Mackay ???? Pin
Jeff Martin22-Mar-05 9:57
Jeff Martin22-Mar-05 9:57 
First off, my name isn't Colin, but I'll try to help you. I'm not sure why you are only wanting 3 out of that query, but I'll try to explain why you are getting the 3 and 4.

The first where clause TypeID in (1, 3) will return all records with a TypeID of 1 or 3, so the following records are there...

1 | John | 1
1 | John | 3
2 | Mary | 3
3 | Betty | 1
3 | Betty | 3
4 | Joe | 1

The next where clause AND ID NOT IN (SELECT ID FROM [VIEW] WHERE TypeID NOT IN (1, 3))

That will return all records with a TypeID of anything other than 1 or 3, which based on your recordset, will be all TypeIDs of 2. So the AND ID NOT IN [subquery] will result in data that looks like...
3 | Betty | 1
3 | Betty | 3
4 | Joe | 1

Combining those two results in both IDs of 3 and 4. I get the idea you are trying to find all IDs that have a TypeID of 1 AND 3, but not 2. So you don't want 4 in the result set since it does not have a record with TypeID of 3. Is that correct?

If so, here is a query that does that (replace test1 with your View name)...

<br />
SELECT	DISTINCT ID<br />
FROM	test1 <br />
WHERE	TypeID IN (1,3)<br />
and	ID IN (SELECT ID FROM test1 WHERE TypeID = 1) <br />
and	ID IN (SELECT ID FROM test1 WHERE TypeID = 3)<br />
and	ID NOT IN (SELECT ID FROM test1 WHERE TypeID = 2)<br />


If that's not what you are after, you'll have to be a little clearer in your question.

Jeff Martin
My Blog
GeneralRe: Colin Angus Mackay ???? Pin
WDI22-Mar-05 10:34
WDI22-Mar-05 10:34 
QuestionColin Angus Mackay ???? Pin
WDI22-Mar-05 9:08
WDI22-Mar-05 9:08 
AnswerRe: Colin Angus Mackay ???? Pin
anonymous19823-Mar-05 9:18
anonymous19823-Mar-05 9:18 
GeneralSql stored procedure vs triggers vs functions Pin
jinnyb22-Mar-05 5:55
jinnyb22-Mar-05 5:55 
GeneralRe: Sql stored procedure vs triggers vs functions Pin
Colin Angus Mackay22-Mar-05 7:13
Colin Angus Mackay22-Mar-05 7:13 
GeneralRe: Sql stored procedure vs triggers vs functions Pin
jinnyb22-Mar-05 9:34
jinnyb22-Mar-05 9:34 
GeneralRe: Sql stored procedure vs triggers vs functions Pin
Edbert P22-Mar-05 18:53
Edbert P22-Mar-05 18:53 
GeneralADO inside win32 services goes boom Pin
Peter Mares22-Mar-05 3:08
Peter Mares22-Mar-05 3:08 
GeneralRe: ADO inside win32 services goes boom Pin
Chris Austin22-Mar-05 17:25
Chris Austin22-Mar-05 17:25 
GeneralRe: ADO inside win32 services goes boom Pin
Peter Mares22-Mar-05 19:51
Peter Mares22-Mar-05 19:51 
GeneralQuery Date Field Type In Access Pin
Tunde Ajibawo22-Mar-05 0:16
Tunde Ajibawo22-Mar-05 0:16 
GeneralRe: Query Date Field Type In Access Pin
Colin Angus Mackay22-Mar-05 7:14
Colin Angus Mackay22-Mar-05 7:14 
GeneralRe: Query Date Field Type In Access Pin
Edbert P22-Mar-05 18:55
Edbert P22-Mar-05 18:55 
GeneralRe: Query Date Field Type In Access Pin
Tunde Ajibawo22-Mar-05 22:09
Tunde Ajibawo22-Mar-05 22:09 
GeneralRe: Query Date Field Type In Access Pin
Edbert P23-Mar-05 11:07
Edbert P23-Mar-05 11:07 
GeneralPackage And Deployment Wizard Pin
Salman Sheikh21-Mar-05 22:48
Salman Sheikh21-Mar-05 22:48 
GeneralRe: Package And Deployment Wizard Pin
rwestgraham22-Mar-05 10:58
rwestgraham22-Mar-05 10:58 

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.