SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Location
    Oklahoma, USA
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with easy query question

    I have an SQL question that I know is easy, but I am a SQL noob.

    I have this query that works;
    SELECT
    MailingsTemp.DATE,
    CMMaster.LAST_NAME,
    CMMaster.FIRST_NAME,
    CMMaster.IDNUMBER

    FROM [CFS].[dbo].[CMMaster]

    INNER JOIN
    MailingsTemp on MailingsTemp.IDNUMBER = CMMaster.IDNUMBER

    I want to add a field from a third table (CMContFile) that also is keyed by the same IDNUMBER

    How do I add the join for the third table?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,084
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Just add an exta INNER JOIN like so

    Code:
    INNER JOIN
    MailingsTemp on MailingsTemp.IDNUMBER = CMMaster.IDNUMBER 
    INNER JOIN
    CMContFile ON CMContFile.IDNUMBER = CMMaster.IDNUMBER
    Then you can add the field(s) you want to select from CMContFile to the SELECT clause of the query.
    Note that you don't have to specify in which order MySQL needs to JOIN the tables. Stating MailingsTemp first and than CMContFile doesn't mean MySQL will join that way. MySQL will figure out the best way to join the tables for itself*.

    * If you really want MySQL to join tables in a particular order --and in 99,9999% of the time there is no reason for this-- you can use the query hint STRAIGHT_JOIN

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Location
    Oklahoma, USA
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a bunch!


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
  •