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 > Database Server Software > MySQL > Newbie select question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-12-04, 22:07
markcasazza markcasazza is offline
Registered User
 
Join Date: Jul 2004
Posts: 5
Newbie select question

I have 2 tables with email addresses. I need to get the email addresses from the "old" table that are not in the "new" table. A DBA I know suggested:
SELECT Email FROM Old WHERE Email NOT IN (SELECT Email FROM New)
It did not work.

TIA

Mark C
Reply With Quote
  #2 (permalink)  
Old 07-13-04, 10:39
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
What does "it did not work" mean?
Did you get no results? Did you get an error message?
what version of MySQL are you running?
Reply With Quote
  #3 (permalink)  
Old 07-13-04, 11:24
markcasazza markcasazza is offline
Registered User
 
Join Date: Jul 2004
Posts: 5
I got an error message pointing to the SELECT in the ().

I am running 3.23.58
Reply With Quote
  #4 (permalink)  
Old 07-13-04, 14:52
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
The reason you are getting an error message is that you can't use subqueries before version 4.1

You can do this with a join though:

Code:
SELECT oldemailaddress 
FROM oldtable AS old
LEFT OUTER JOIN 
newtable as new
ON old.oldemailaddress = new.newemailaddress
WHERE new.newemailaddress IS NOT NULL
Reply With Quote
  #5 (permalink)  
Old 07-13-04, 18:27
markcasazza markcasazza is offline
Registered User
 
Join Date: Jul 2004
Posts: 5
Not quite, but close. For the sake of anyone reading this later the following worked:

SELECT old.email FROM oldemail AS old LEFT OUTER JOIN newemail AS new ON old.email = new.email WHERE new.Email IS NULL

Thanks for the help!!
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