I have two columns on one table that reference the same column on a second table in order to obtain the name that relates to an specified ID.
Below is the query that I am using that is not working. The two LEFT JOINS on the invTypes causes the problem. I have read and read and have been racking my brain on this. I cannot for the life of me figure out how to make this return the names that belong to the IDs that appear in two separate locations in the main table.
THings to note with out posting the entire database structure (which is huge)
both the typeID and itemTypeID are present on the main table. Each of those references the same typeID column in the invTypes table. The invTypes table contains the name that corresponds to said ID.
Additionally, in the SELECT part of the statement, the typeName comes from the invTypes and the stationName comes from the staStations table.
The main question is, if the invTypes.typeName is referenced two times from two columns, how do i 1: properly join the tables to those two points and 2: how do i tell the difference in the two invTypes.typeName that is to be returned if the two JOIN statements can be made.
SELECT
`logTime`,`itemID`,`typeName`,`actorName`,`stationName`,`action`,`passwordType`,
`quantity`,`oldConfiguration`,`newConfiguration`
FROM eve_container_audit
LEFT JOIN invTypes ON eve_container_audit.typeID = invTypes.typeID
LEFT JOIN invTypes ON eve_container_audit.itemTypeID = invTypes.typeID
LEFT JOIN staStations ON eve_container_audit.locationID = staStations.stationID
Here’s how to join them just once :
If you need to join them twice, use alias :