i have an information table that has the following fields in it;
id, staffMember, lineManager, description
The staffMember and lineManager fields return integer values that correspond to the id of rows within a users table which has the following columns
id, firstname, surname
I can use the following query to return the info in my information table, substituting the staffMember value for a CONCAT of firstname and surname:
SELECT information.id,
CONCAT( users.firstname, ' ', users.surname ) AS staffMember,
information.lineManager,
LEFT(information.description,200) As description
FROM information
LEFT JOIN users
ON ( information.staffMember = users.id )
LIMIT 0 , 30"
But what i want to be able to do, is repeat the process that’s working on the value of staffMember on lineManager as well in the same query (which i then pass as a json string) – however, i know i can’t have two LEFT joins to the same table but equating different fields.
Any help would be gratefully received.
It sounds like you want this:
You just perform a
LEFT JOINon theuserstable twice. Once you will join on thestaffMemberand the other time you will join onlineManager. By providing a different table alias to the table you can distinguish between the tables and the values.Of if you want to be clearer: