February 2, 2011 at 8:39 am
I have an issue with restricting records with multi-part keys.
Table A (Key1 INT, Key2 INT, Data...)
Table B (Key1 INT, Key2 INT, DATA...)
So I want to write a query that is
SELECT everything from table A except where it's in table B
I can think of quite a few logical ways to do this but have not found the proper syntax. I always end up doing some work around but I think there has to be a way.
Any suggestions? Thanks in advance.
John
February 2, 2011 at 11:26 am
Sorry if this is oversimplifying your query, but do you just mean:
SELECT * FROM Table1 EXCEPT (SELECT * FROM Table2) ?
Example:
CREATE TABLE #A(
a int,
b int)
INSERT INTO #A SELECT 5,1
INSERT INTO #A SELECT 6,1
INSERT INTO #A SELECT 7,1
CREATE TABLE #B(
a int,
b int)
INSERT INTO #B SELECT 4,1
INSERT INTO #B SELECT 6,1
INSERT INTO #B SELECT 7,1
SELECT * FROM #A EXCEPT (SELECT * FROM #B)
February 2, 2011 at 11:42 am
That does what I'm looking for.
I wonder how the performance is on something like that?
Thank you
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply