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!

Join doesn not work...Help

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
I have two tables say Table1 and Table2. Both the tables have a number of columns, but the ones I am looking at are called ID, PhoneID, Description. Both the tables have these common columns. Here is what I am trying to do. Suppose TABLE1 has this data.

--------Table1---------
ID PhoneID Description
5 1 Nokia
7 2 Motorola
10 3 Samsung

Now if Table2 has following info--

-------Table2-----------

ID PhoneID Description
3 3 Samsung

Now I want my query to return ONLY those entries from table1 that do not exsist in Table2. So Nokia and Motorola should be returned in the above example. Table2 could have multiple entries of the same name. So it could have PhoneID 3 Samsung twice.

I wrote something like this but it doesnt seem to work.

Code:
SELECT t1.*
FROM Table1 t1,Table2 t2
WHERE t1.EventID <> t2.EventID

Any help would be appreciated.
 
When I said EventID I meant PhoneID. So

SELECT t1.*
FROM Table1 t1,Table2 t2
WHERE t1.PhoneID <> t2.PhoneID

Why do u do the IS NULL Part?
 
why do i do the IS NULL part?

because that's how you return only those rows from t1 that do not have a matching row in t2

the important part is that it's a LEFT OUTER JOIN

your query returns almost a complete CROSS JOIN

do you know the difference between types of joins?

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (course starts January 9 2005)
 
Yeah I do...But this is what happens when you dont use them very often. Thanks a lot. I am gonna play with this and read up on it.
 
Yeah sort off. Thanks a lot for all the help. I think I should read up a little bit on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top