1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development MySQL PHP Table join Problem NEED HELP FAST

Discussion in 'Software' started by Draxin, 17 Jul 2007.

  1. Draxin

    Draxin Seeker of Photons

    Joined:
    29 Nov 2001
    Posts:
    965
    Likes Received:
    5
    Here is the query

    PHP:
    $sql_inventory mysql_query("SELECT `id`,`name`,`description`,`cat`,`subcat`,`owner`,`qty` FROM `inventory` INNER JOIN `clients` ON `inventory`.`owner` = `clients`.`id` ORDER BY `clients`.`name` ASC") or die("query fail : "mysql_error());
    PHP keeps coming back with "Column 'id' in field list is ambiguous"


    is there any easy fix to this that doesnt require me to rename columns in the database?

    Please help, im kind of in a time crunch.

    thanks guys
     
  2. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    Code:
    $sql_inventory = mysql_query("SELECT `inventory`.`id`,`inventory`.`name`,`inventory`.`description`,`inventory`.`cat`,`inventory`.`subcat`,`inventory`.`owner`,`inventory`.`qty` FROM `inventory` INNER JOIN `clients` ON `inventory`.`owner` = `clients`.`id` ORDER BY `clients`.`name` ASC") or die("query fail : ". mysql_error());
     
  3. Draxin

    Draxin Seeker of Photons

    Joined:
    29 Nov 2001
    Posts:
    965
    Likes Received:
    5
    if i could i would hug you RTT

    i thought the FROM `inventory` would have made that clear to MySQL but i was wrong

    THANK YOU THANK YOU THANK YOU
     
  4. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    You need to specify which table you want id from inventory.id or clients.id rather than just id, probably the same with the rest of the fields.

    Code:
    SELECT inventory.id, .....
    or
    Code:
    SELECT clients.id, .....
    If both tables have a field with the same name and you want both you will need to use AS
    Code:
    SELECT inventory.id AS invid, clients.id AS clientid
    edit: bah to slow
     
    Last edited: 17 Jul 2007
  5. Draxin

    Draxin Seeker of Photons

    Joined:
    29 Nov 2001
    Posts:
    965
    Likes Received:
    5
    Thanks anyway ben. appreciate the speedy replies
     
  6. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    You'd think so but there are some good reasons why that doesn't make it clear to MySQL. You'd have to dig into some pretty hefty theory though ;)
     

Share This Page