Click here to Skip to main content
15,891,951 members
Home / Discussions / Database
   

Database

 
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 
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 
Okay - I've added some extra SQL to the statement I wrote previously. I couldn't think of a very elegant solution to this so it is actually in two parts. First I create and populate a temporary table (actually a table variable) with similar results to the query that you have already. (I remove the distinct and add the TypeID column to the output). Secondly, I take the results of the first part and perform a self-join (in other words I join the table to itself) so that I can find only those that have all the relevant TypeIDs rather than just any of the typeIDs.
-- Create and populate the table variable
DECLARE @ids TABLE(ID int, TypeID int)
INSERT INTO @ids
SELECT DISTINCT ID, TypeID FROM [VIEW]
WHERE TypeID IN (1,3)
AND ID NOT IN (SELECT ID FROM [VIEW]
               WHERE TypeID NOT IN (1,3)) 
-- The final result comes from the table variable.
SELECT DISTINCT a.ID
FROM @ids AS a
INNER JOIN @ids AS b on a.id = b.id -- self-join
WHERE a.TypeID = 1 AND b.TypeID = 3 -- Ensure that the ID has both desired typeIDs


Does this help?


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


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 
GeneralManaged Provider for Oracle Pin
satishrg16-Mar-05 13:26
satishrg16-Mar-05 13:26 
QuestionDTS and Identity column? Pin
devvvy15-Mar-05 14:33
devvvy15-Mar-05 14:33 

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.