SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    865
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    A question about joining two tables

    I must be overlooking something. The following query returns 432 rows:

    select * from users where sponsorID = '0' and sponsorUpdated is not null and uID not in (select uID from communications where type = 'Account Change' and entry like '%be 110%') limit 5000;


    This join produces 23 results:

    select count(*) from users u join communications c on u.uID = c.uID where u.sponsorID = '0'
    and u.sponsorUpdated is not null and c.entry like '%110%';

    Thoughts?
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    the first query is actually an "exception" join -- rows from the users table that don't have a matching row in the communications table

    the second query is a conventional inner join -- rows from the users table that do have a matching row in the communications table

    i'm not sure what it is that you were wondering about
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •