I have the following two tables:
system
- id
- systemName
- idOrganization
organization
- id
- officeSymbol
I am running the following query and receiving an id
is ambiguous error:
SELECT system.systemName, organization.officeSymbol
FROM system
LEFT JOIN (organization)
ON (system.idOrganization = organization.id)
As you can see, I'm not selecting the id
column. If I place system.id
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 id
- we don't want it displayed to the user.
Also, if I add GROUP BY system.systemName
I no longer get the error - but this just doesn't seem like the optimal solution.
Note: The LEFT JOIN
is intentional as not all systems will be assigned to an 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;