SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to grab a column in one query - cannot see how

    Hi all,

    I have a couple of tables and need to get one piece of data from them in a single query but cannot figure out how to do it - although I am pretty sure it is possible.

    I have the variable available for "CAMPCRE_ID" and I have the following -

    TABLE - CAMPCRE

    CAMPCRE_ID
    CC_ID

    TABLE - CRE

    CC_ID
    NAME

    I need to get NAME AND CC_ID in a single query but I cannot see how? I can get CC_ID where CAMPCRE_ID = $var, but cannot progress (in one query) to then grab NAME from the other table.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    SitePoint Addict
    Join Date
    Sep 2007
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Read the link recommended guido2004, in case you need it fast, here's how to do it:

    Code:
      SELECT c.cc_id, c.name
      FROM campcre cc
                INNER JOIN 
               cre c
                    ON cc.cc_id = c.cc_id
      WHERE cc.campcre_id = $var

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks both.

    Managed to do it after reading the link - I knew it was join but could not remember what it was called!


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
  •