SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql table joins

    Okay,

    so after banging my head on the keyboard for about an hour - I give up. Does anyone know how I would do this, or if I even could?....


    PHP Code:
    I have two tables:
    ----------------------------
    categories:
    ---------------------------
    catid name
    1       this is the firstname
    2       this is the secondname

    ----------------------------
    access:
    ----------------------------
    groupid catid
    1         2

    I want to select only the items from access where groupid 
    1
    but all of the ones from categoriesregardlessI need a 
    result that looks like
    :

    catid groupid name
    1                 this is the firstname
    2      1       this is the secondname 

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to use a left outer join. You can read a bit about them ins the mysql manual in the chapter/section that deals with SELECT queries and also an article here http://www.devshed.com/Server_Side/M...oin/page4.html

    Something like this should work:
    Code:
    SELECT categories.catid AS catid, groupid, name
    FROM categories LEFT JOIN access ON categories.catid = access.catid


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
  •