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 8473271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:18:15+00:00 2026-06-10T17:18:15+00:00

I have an enquiry about MySQL statement about combining two rows in a table

  • 0

I have an enquiry about MySQL statement about combining two rows in a table using sql statement. Initially, I have implemented codes to show in the data grid view the employee’s shift.

LocationName | StationName | 12:00 - 13:00 | 13:00 - 14:00 | 14:00 - 15:00
T2           | Counter     | Michael Joyce | Michael Joyce | Michael Joyce

As you can see, there were two employees under the same Location and Station. Next step, I’m going to use SQL statement to type out the format and eventually used the SQL statement to reportviewer.

This is the SQL statement that I tried to show to the same format as shown above.

select
  z.LocationName,
  z.StationName,
  a.12001300,
  b.13001400,
  c.14001500
from (SELECT DISTINCT
        LocationName,
        StationName
      FROM satsschema.employeeslot
      where AllocationDate = '10-Aug'
          and LocationName = 'T2 PML'
          and StationName is not null) z
  left outer join (SELECT
                     LocationName,
                     StationName,
                     EmpName         AS '12001300'
                   FROM satsschema.employeeslot
                   WHERE Assigned = true
                       and AllocationDate = '10-Aug'
                       and (EmpTime = '12:00:00' && EmpTime < '13:00:00')) a
    on z.LocationName = a.LocationName
      and z.StationName = a.StationName
  left outer join (SELECT
                     LocationName,
                     StationName,
                     EmpName         AS '13001400'
                   FROM satsschema.employeeslot
                   WHERE Assigned = true
                       and AllocationDate = '10-Aug'
                       and (EmpTime = '13:00:00' && EmpTime < '14:00:00')) b
    on a.LocationName = b.LocationName
      and a.StationName = b.StationName
  left outer join (SELECT
                     LocationName,
                     StationName,
                     EmpName         AS '14001500'
                   FROM satsschema.employeeslot
                   WHERE Assigned = true
                       and AllocationDate = '10-Aug'
                       and (EmpTime = '14:00:00' && EmpTime < '15:00:00')) c
    on b.LocationName = c.LocationName
      and b.StationName = c.StationName

This SQL statement shown above showed the following results that did not match what I wanted. It shows like this:

LocationName | StationName | 12:00 - 13:00 | 13:00 - 14:00 | 14:00 - 15:00
T2           | Counter     | Michael       | Michael       | Michael

As you can see, It only shows one employee in the Location and Station only. How could be done to the SQL statement that I could also see other employees if there were more then one inside the Location and Station. Any opinions?

  • 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-06-10T17:18:16+00:00Added an answer on June 10, 2026 at 5:18 pm

    Use GROUP_CONCAT. See Can I concatenate multiple MySQL rows into one field?

    Something along the lines of:

    SELECT z.LocationName, z.StationName, Block12.EmpList, Block13.EmpList, Block14.EmpList
    FROM satsschema.employeeslot z
    LEFT OUTER JOIN
    (
        SELECT LocationName, StationName, GROUP_CONCAT(EmpName) AS EmpList
        FROM satsschema.employeeslot
        WHERE Assigned = true
            AND AllocationDate = '10-Aug'
            AND (EmpTime = '12:00:00' && EmpTime < '13:00:00')
        GROUP BY LocationName, StationName
    ) Block12
    ON z.LocationName = Block12.LocationName
        AND z.StationName = Block12.StationName
    LEFT OUTER JOIN
    (
        SELECT LocationName, StationName, GROUP_CONCAT(EmpName) AS EmpList
        FROM satsschema.employeeslot
        WHERE Assigned = true
            AND AllocationDate = '10-Aug'
            AND (EmpTime = '13:00:00' && EmpTime < '14:00:00')
        GROUP BY LocationName, StationName
    ) Block13
    ON z.LocationName = Block13.LocationName
        AND z.StationName = Block13.StationName
    LEFT OUTER JOIN
    (
        SELECT LocationName, StationName, GROUP_CONCAT(EmpName) AS EmpList
        FROM satsschema.employeeslot
        WHERE Assigned = true
            AND AllocationDate = '10-Aug'
            AND (EmpTime = '14:00:00' && EmpTime < '15:00:00')
        GROUP BY LocationName, StationName
    ) Block14
    ON z.LocationName = Block14.LocationName
        AND z.StationName = Block14.StationName
    WHERE AllocationDate = '10-Aug'
    GROUP BY z.LocationName, z.StationName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a enquiry about creating view in MySQL workbench. I have error: View's
I have two classes, ThreadItem and Enquiry. public class ThreadItem { [Key] public int
I'm trying to have a table with sortable rows - but also one of
I have two tables, one called Events and one called Documents. Each table has
Using CSS Style Sheet In my web page, i have two class like menu
I have an enquiry form on a site, which has been working for a
have 2 questions : A computer with 32-bit address uses 2-level page table (9
Is it possible to send the enquiry email to two addresses with the code
Struggling with this one. I have set up a basic email/enquiry form for a
I have a problem where the server I'm using is not configured to allow

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.