SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I select items from 1 table that are not in another?

    Hello everybody,
    I am running a mail program, and it crashed in mid session. So I need to restart it but only using email addresses that the email was not sent to.

    I have one table of email addresses, which has the fields

    id,email, country

    and another, called logs

    id, email, date

    How do I select all the emails in the first table that are not in the second?

    Thanks in advance.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    London
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this
    Code SQL:
    SELECT email FROM addresses WHERE
    email NOT IN (SELECT email FROM logs);

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    alternatively,
    Code:
    SELECT addresses.email
      FROM addresses
    LEFT OUTER
      JOIN logs
        ON logs.email = addresses.email
     WHERE logs.email IS NULL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool guys, thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •