Note that there are some explanatory texts on larger screens.

plurals
  1. POAmbiguous `id` Field
    primarykey
    data
    text
    <p>I have the following two tables:</p> <pre><code>system - id - systemName - idOrganization organization - id - officeSymbol </code></pre> <p>I am running the following query and receiving an <code>id</code> is ambiguous error:</p> <pre><code>SELECT system.systemName, organization.officeSymbol FROM system LEFT JOIN (organization) ON (system.idOrganization = organization.id) </code></pre> <p>As you can see, I'm not selecting the <code>id</code> column. If I place <code>system.id</code> within the list of fields to select, I no longer receive this error. Unfortunately, the manner in which this data is handled I can't return the <code>id</code> - we don't want it displayed to the user.</p> <p>Also, if I add <code>GROUP BY system.systemName</code> I no longer get the error - but this just doesn't seem like the optimal solution.</p> <p>Note: The <code>LEFT JOIN</code> is intentional as not all systems will be assigned to an Organization.</p> <pre><code>SELECT VERSION() --&gt; 5.0.77-community-log CREATE TABLE system ( `id` INT(11) NOT NULL AUTO_INCREMENT, `systemName` VARCHAR(45) DEFAULT NULL, `idOrganization` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_system_organization` (`idOrganization`), CONSTRAINT `fk_system_organization` FOREIGN KEY (`idOrganization`) REFERENCES `organization` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE organization ( `id` INT(11) NOT NULL AUTO_INCREMENT, `officeSymbol` VARCHAR(45) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload