SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    I need to create a rather complex MySQL query.

    Hi,

    I need to create a rather complex MySQL query.
    Here is the description:

    I want a query which generates a Table from 5 Tables, but what it finds in Tables 1 through 4 must not be in Table 5.
    Put another way in regular language with some MySQL interjected in it, this is what should happen:

    SELECT distinct(email) FROM Table, T1, T2, T3, T4, T5
    Where date <x and date > y for looking into T1, T2, T3, T4
    AND the email that you find in T1, T2, T3, T4 for this date range does not exist in T5 for the entire date range of T5.

    Some more background info: Tables T1, T2, T3, T4 have a few million records in them over their 4 year date range.
    T5 has few 1000 records in it during the same date range.

    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The trick will be to use a LEFT JOIN on T5 and, in your WHERE clause, filter for records that report a value of NULL (i.e. no record found) for the T5 primary key column.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Kevin,

    Can you please be specific in the code that should be used here.
    I mean give me the actual MySQL code for what should happen here.
    Just to be sure.

    Regards,

    P.S., I bought your books:Simply JavaScript | BYO PHP/MySQL

    Quote Originally Posted by Kevin Yank View Post
    The trick will be to use a LEFT JOIN on T5 and, in your WHERE clause, filter for records that report a value of NULL (i.e. no record found) for the T5 primary key column.

    Anoox search engine volunteer

    www.anoox.com


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
  •