Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to compare two columns in on

Status
Not open for further replies.

wuwang

Programmer
Joined
May 16, 2001
Messages
48
Location
US
I want to compare two columns in one table.
Col_1 has more data than col2 and I want to find out
which data not exist in col2.

Could you tell me where my code is wrong?

select distinct t1.col_1 from table1 t1
where t1.col_1 NOT IN (
select distinct col_2 from table1)

Thanks a lot
 

There's nothing wrong with the query syntax. You didn't mention why you think it is not working so we are left to guess at the problem. Please tell us what the problem is.

Thanks, Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Sorry for not clear meaning.

Col_1 has 38 records and col_2 has 5 records. When I run the query and it keeps running for 1 more minutes and there
is no any output.
So I cancelled the running and thought there is something wrong.

 

I don't know any reason that query should run more than a fraction of a second if the table only has 38 records. However, I'm unclear still about the content of the table.

Does it only contain 38 records? Or do you mean that 38 records have something in Col_1 and 5 records have something in Col_2? How many records are on the table? If there are more than 38 records, are Col_1 and Col_2 NULL in those records?

Maybe you need to modify your query as follows.

Select col_1
From table1 t1
Where Col_1 IS NOT NULL
And col_1 NOT IN
(Select col_2 from table1
WHERE col_2 IS NOT NULL) Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top