Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 579569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:22:50+00:00 2026-05-13T14:22:50+00:00

I have four tables I want to join and get data from. The tables

  • 0

I have four tables I want to join and get data from. The tables look something like…

  • Employees (EmployeeID, GroupID[fk], EmployeeName, PhoneNum)
  • Positions (PositionID, PositionName)
  • EmployeePositions (EployeePositionID, EmployeeID[fk], PositionID[fk])
  • EmployeeGroup (GroupID, GroupName)

[fk] = foreign key

I want to create a query that will return all the information about an employee(given by EmployeeID). I want a query that will return the given employees Name, position(s), and group in one row.

I think it needs to involve joins, but I am not sure how to format the queries. MYSQL’s manual is technical beyond my comprehension. I would be very grateful for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:22:50+00:00Added an answer on May 13, 2026 at 2:22 pm

    It seems you have trouble with SQL, in general, rather than with mySQL in particular. The documentation of mySQL provides details about the various SQL expressions, but generally assume some familiarity with SQL. To get a quick start on SQL you may consider this W3schools.com primer.
    The query you need is the following.

    SELECT EmployeeName, PositionName, GroupName
    FROM Employees E
    LEFT JOIN EmployeePositions EP ON EP.EmployeeID = E.EmployeeID
    LEFT JOIN Positions P ON P.PositionID = EP.PositionId
    LEFT JOIN EmployeeGroup EG ON EG.GroupId = E.GroupId
    WHERE E.EmployeeId = some_value
    

    A few things to note:
    The ‘LEFT’ in ‘LEFT JOIN’ will result in producing NULL in lieu of PositionName or GroupName when the corresponding tables do not have a value for the given FK. (Should only happen if the data is broken, say if for example some employees have GroupId 123 but somehow this groupid was deleted from the EmployeeGroup table.
    The query returns one line per employee (1). You could use an alternative search criteria, for example WHERE EmployeeName = ‘SMITH’, and get a listing of all employees with that name. Indeed without a WHERE clause, you’d get a list of all employees found in Employees table.
    (1) that is assuming that each employee can only have one position. If somehow some employees have more than one position (i.e. multiple rows in EmployeePositions for a given EmployeeID), you’d get several rows per employee, the Name and Group being repeated and a distinct PostionName.

    Edit:
    If a given employee can have multiple positions, you can use the query suggested by Tor Valamo, which uses a GROUP BY construct, with GROUP_CONCAT() to pivot all the possible positions in one single field value in the returned row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four tables in my database and i want to join that's and
I want to join two tables together and have ONLY the data in Table
Have 4 relationship tables in my database and want to join them to get
I have four tables containing exactly the same columns, and want to create a
i have four tables like below in sql server 2008 : TABLE 1 ->
I have a number of tables with text around them describing them. Something like
I am wanting to have a view table that aggregates rows from four tables.
I have four tables like the following : Cars: car_id | make_id 1 |
I have four Database Tables like these: Book ID_Book |ID_Company|Description BookExtension ID_BookExtension | ID_Book|
I have four tables, Shops Sales Batches Products and I would like to extract

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.