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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUERY TWO TABLES PROBLEM

Status
Not open for further replies.

seg101

Programmer
Nov 24, 2002
2
GB
I am having a problem with querying two tables!

I have two tables, say table_one and table_two. These two tables have a similar field, say table_one.field and table_two.field.

I wish to select all of the table_two records appart from the ones where table_two.field = table_one.field.

For example if table_one.field held the following records:

item1
item6
item19

and table_two.field held:

item1
item4
item6
item9
item16
item19

I would expect the output of the SQL query to be:

item4
item9
item16

I would be very greatfull if someone could please advise me.

Sam
 
Try this:

SELECT table_two.fields FROM table_two LEFT JOIN table_one ON table_one.fields=table_two.fields WHERE table_one.fields IS NULL ;
 
Thanks, but this just appears to return the empty set...
 
the required should simply be:

SELECT * FROM table_one, table_two WHERE table_one.field != table_two.field;

try this...


 
... sorry the above is wrong just re-read your initial entry... I'll have a re-think !

 
... i should also have said that the above my query is only OK if table_two contains all of the same AND different entries to table_one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top