If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Problem returning data twice

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-28-04, 14:32
tonycavanagh tonycavanagh is offline
Registered User
 
Join Date: Feb 2004
Posts: 10
SQL Problem returning data twice

I have two tables EMPLOYEE and WORKING, I want to do a select on the table EMPLOYEE that returns all EMPLOYEES not working.

I use the following SQLPLUS Select statment.

select emp.name
from EMPLOYEE emp,WORKING wk
where wk.employeeID!= emp.employeeID;

Lets say TOM SMITH is working, but Susan Thomas and Steve Jones is not.

what this command returns is

Susan Thomas
Steve Jones
Tom Smith
Susan Thomas
Steve Jones


If I run the select satement
select emp.name
from EMPLOYEE emp,WORKING wk
where wk.employeeID = emp.employeeID;

It only returns

Tom Smith

There is a problem with the !=.

Thanks for any help

Tony
Reply With Quote
  #2 (permalink)  
Old 02-28-04, 19:53
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Select ta.*
from tableA ta
LEFT OUTER JOIN
tableB tb ON
ta.id = tb.id
where tb.id IS NULL;

Alternatively,

Select ta.*
from tableA
where id NOT IN
(select id
from tableB);
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #3 (permalink)  
Old 03-01-04, 05:48
tonycavanagh tonycavanagh is offline
Registered User
 
Join Date: Feb 2004
Posts: 10
Thanks they both worked.

Cheers Tony
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On