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

Database

 
GeneralSELECT TOP Pin
vuthaianh25-Mar-05 12:10
vuthaianh25-Mar-05 12:10 
GeneralRe: SELECT TOP Pin
turbochimp25-Mar-05 17:49
turbochimp25-Mar-05 17:49 
GeneralSimplify a T-SQL Pin
WDI25-Mar-05 7:41
WDI25-Mar-05 7:41 
GeneralRe: Simplify a T-SQL Pin
Michael Potter25-Mar-05 8:24
Michael Potter25-Mar-05 8:24 
GeneralRe: Simplify a T-SQL Pin
WDI25-Mar-05 9:10
WDI25-Mar-05 9:10 
GeneralRe: Simplify a T-SQL Pin
Michael Potter25-Mar-05 11:34
Michael Potter25-Mar-05 11:34 
GeneralRe: Simplify a T-SQL Pin
Tony Lewis25-Mar-05 9:41
Tony Lewis25-Mar-05 9:41 
GeneralRe: Simplify a T-SQL Pin
andyharman28-Mar-05 4:32
professionalandyharman28-Mar-05 4:32 
I used the following method a few years back:
SELECT ID FROM T
WHERE TypeId IN (i, j, k)
GROUP BY ID
HAVING COUNT(DISTINCT TypeId) = 3
Where "3" is the number of terms in the "IN" clause. To handle your "NOT IN" requirement, you could use the following:
SELECT ID FROM T
WHERE ID IN (SELECT ID FROM T
    WHERE TypeId IN (i, j, k)
    GROUP BY ID
    HAVING COUNT(DISTINCT TypeId) = 3)
GROUP BY ID
HAVING COUNT(DISTINCT TypeId) = 3
I don't know how fast this will run against your chosen database engine. Under SQL-Server, I would normally expect the following indexes to help:
Clustered index on T (ID, TypeId)

And possibly:
Nonclustered index on T (TypeId)


Hope this helps.

Regards
Andy
GeneralDateTime Pin
vuthaianh25-Mar-05 5:24
vuthaianh25-Mar-05 5:24 
GeneralRe: DateTime Pin
Colin Angus Mackay25-Mar-05 6:29
Colin Angus Mackay25-Mar-05 6:29 
QuestionSQL problem ? Pin
Guinness4Strength25-Mar-05 4:28
Guinness4Strength25-Mar-05 4:28 
QuestionMultiple insert in single roundtrip with Sqlcommand, Possible??? Pin
abcxyz8225-Mar-05 4:11
abcxyz8225-Mar-05 4:11 
AnswerRe: Multiple insert in single roundtrip with Sqlcommand, Possible??? Pin
ToddHileHoffer25-Mar-05 4:35
ToddHileHoffer25-Mar-05 4:35 
GeneralRe: Multiple insert in single roundtrip with Sqlcommand, Possible??? Pin
Colin Angus Mackay25-Mar-05 6:32
Colin Angus Mackay25-Mar-05 6:32 
AnswerRe: Multiple insert in single roundtrip with Sqlcommand, Possible??? Pin
_J_25-Mar-05 7:19
_J_25-Mar-05 7:19 
AnswerRe: Multiple insert in single roundtrip with Sqlcommand, Possible??? Pin
_J_25-Mar-05 11:19
_J_25-Mar-05 11:19 
QuestionHow to ROLLBACK TRANSACTION on client level Pin
_J_25-Mar-05 3:32
_J_25-Mar-05 3:32 
AnswerRe: How to ROLLBACK TRANSACTION on client level Pin
Luis Alonso Ramos25-Mar-05 12:21
Luis Alonso Ramos25-Mar-05 12:21 
AnswerRe: How to ROLLBACK TRANSACTION on client level Pin
turbochimp25-Mar-05 18:02
turbochimp25-Mar-05 18:02 
GeneralRe: How to ROLLBACK TRANSACTION on client level Pin
_J_25-Mar-05 23:56
_J_25-Mar-05 23:56 
Generalreturning table from a stored procedure Pin
balkang25-Mar-05 2:52
balkang25-Mar-05 2:52 
GeneralRe: returning table from a stored procedure Pin
_J_25-Mar-05 3:00
_J_25-Mar-05 3:00 
GeneralRe: returning table from a stored procedure Pin
balkang25-Mar-05 23:25
balkang25-Mar-05 23:25 
GeneralIs Insert, Delete, Update already have transaction Pin
_J_25-Mar-05 1:59
_J_25-Mar-05 1:59 
GeneralRe: Is Insert, Delete, Update already had transaction Pin
Colin Angus Mackay25-Mar-05 2:07
Colin Angus Mackay25-Mar-05 2:07 

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.