I have the following two tables:
system - id - systemName - idOrganization organization - id - officeSymbol
I run the following query and get id ambiguous error:
SELECT system.systemName, organization.officeSymbol FROM system LEFT JOIN (organization) ON (system.idOrganization = organization.id)
As you can see, I do not select the id column. If I put system.id in the list of fields for selection, I no longer get this error. Unfortunately, the method of processing this data I can not return id - we do not want it to be displayed to the user.
Also, if I add GROUP BY system.systemName , I no longer get the error, but it just doesn't seem like the optimal solution.
Note. LEFT JOIN is intentional because not all systems will be assigned to the organization.
SELECT VERSION() --> 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;
source share