August 3, 2005 at 3:39 pm
Hi
I have table1 with a column "id" and
table2 with a column "id". The id column is supposed to be the same in both the tables...but does not.
I am trying to write a query that will list the id's (records) from both the tables that do not match. Can someone help me with this query.
Thanks
August 3, 2005 at 5:19 pm
select 'in table1 not table2' Type, t1.id from table1 t1 where t1.id not in (select t2.id from table2 t2)
union
select 'in table2 not table1' Type, t3.id from table2 t3 where t3.id not in (select t4.id from table1 t4)
order by 1
August 4, 2005 at 6:55 am
Wouldn't it be faster to just do a full outer join where either id is null??
August 4, 2005 at 10:00 am
>>Wouldn't it be faster to just do a full outer join where either id is null?? <<
YES:
select (case when t2.id is null then 'in table1 not table2' else 'in table2 not table1' end) Type
, coalesce(t1.id,t2.id) TheID
from
table1 t1 full outer join table2 t2 on t1.id =t2.id
where
t1.id is Null or t2.id is null
order by Type
* Noel
August 4, 2005 at 10:07 am
Nice to see you back online... been almost 2 days now .
August 4, 2005 at 10:11 am
Yes, it is nice to be back but probably will have to take a second break on my next two weeks in london (Job stuff!)
* Noel
August 4, 2005 at 10:18 am
Damn... do you need an assitant, maybe a junior DBA .
August 4, 2005 at 10:23 am
Hey, you guys are ganging up on me ... it was late, I was tired & just trying to help
Anyway, my solution requires only one line and does not depend on the ability to spell coalesce
August 4, 2005 at 10:30 am
hey Phil,
I just posted "another" way, never though of it as "ganging on you"
* Noel
August 4, 2005 at 10:37 am
No we're not... just stating that there might be a better way.
BTW I was actually serious about the junior DBA position .
August 4, 2005 at 10:46 am
BTW I was actually serious about the junior DBA position
Don't worry I am pretty sure you will do well. If something comes up I'll let you know
* Noel
August 4, 2005 at 10:55 am
I'm really thinking to upgrade and move to the us... warmer climate funnier job, better conditions (hopefully). Closer to the us pool tour . Where do you work exactly?
August 4, 2005 at 11:01 am
NY.
Still trying to figure out where sushila works though
* Noel
August 4, 2005 at 11:23 am
I heard maybe NY or london... but she also said to me tha she lived in China so I have no clue.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply