help with mySQL query

I have a query that I need to pull an additional column into. I am having a moment of dead grey matter and need help.

query as is

SELECT g.groupId,g.name AS groupName,l.logId,l.name AS logName, i.itemID,
      i.name AS itemName, le.userName,completed, i.optimalMin,i.optimalMax ,le.value,
      u.name AS unitDescription,g.parentId
  FROM logExceptions le
      INNER JOIN logs l ON l.logID = le.logID
      INNER JOIN groups g ON g.groupId = l.groupId
      INNER JOIN items i ON le.itemId = i.itemId
      INNER JOIN units u ON i.unitId = u.unitId
 

Open in new window


I need to pull the label  for the parentId into the query - the label is another row tied to the groupID in the groups table

group name 1group name 2
So I need to pull the name 'root group' into the above query
portlightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

portlightAuthor Commented:
SOLUTION

    SELECT g.groupId,g.name AS groupName,l.logId,l.name AS logName, i.itemID,
    i.name AS itemName, le.userName,completed, i.optimalMin,i.optimalMax ,le.value,
    u.name AS unitDescription,g.parentId,g1.name AS parentName
    FROM logExceptions le
    INNER JOIN logs l ON l.logID = le.logID
    INNER JOIN groups g ON g.groupId = l.groupId
    INNER JOIN items i ON le.itemId = i.itemId
    left JOIN groups g1 ON g.parentId = g1.groupId
    INNER JOIN units u ON i.unitId = u.unitId
0
arnoldCommented:
Are the group only go one level down? Parent/child only or parent/child/grandchild?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
InsoftserviceCommented:
Please provide complete schema of all your tables.
First of all you have used inner join to groups and left join to groups again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.