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

  • SEARCH
  • Home
  • 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 7776651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:56:16+00:00 2026-06-01T17:56:16+00:00

This query produces the right answer: SELECT users.*, SUM(overtime_list.shift_length) AS overtime_total, (SELECT GROUP_CONCAT(users_roles.role_ID) FROM

  • 0

This query produces the right answer:

SELECT users.*,
        SUM(overtime_list.shift_length) AS overtime_total,
        (SELECT GROUP_CONCAT(users_roles.role_ID) FROM users_roles WHERE users.user_ID = users_roles.user_ID) AS roles
    FROM availability_list
    INNER JOIN users
        ON users.user_ID = availability_list.user_ID
    INNER JOIN stations
        ON users.station_ID = stations.station_ID
    INNER JOIN overtime_list
        ON overtime_list.user_ID = users.user_ID
        AND overtime_list.date >= '$totalovertimedays'
    WHERE availability_list.date = '$date'
    AND availability_list.type = '$type'
    GROUP BY users.user_ID
    ORDER BY overtime_total ASC

output:

 +----------+---------+----------------------------+------------------+
 |  user_ID | user    |   roles                    |  overtime_total  |
 +----------+---------+----------------------------+------------------+
 |        1 |   Smith |    1,2                     |        12        |
 +----------+---------+----------------------------+------------------+
 |        2 |   Jones |    1,2,3                   |        7         |
 +----------+---------+----------------------------+------------------+

This is the desired result:

 +----------+---------+----------------------------+------------------+
 |  user_ID | user    |   roles                    |  overtime_total  |
 +----------+---------+----------------------------+------------------+
 |        1 |   Smith |    Admin, Staff            |        12        |
 +----------+---------+----------------------------+------------------+
 |        2 |   Jones |    Admin, Staff, Other     |        7         |
 +----------+---------+----------------------------+------------------+

This is a join I can use, which seems to allow the group_concat to correct join “admin, staff, other” – but I cant work out how to incorporate it into the main query above?

SELECT users.user_id, GROUP_CONCAT(roles.short_name  separator ', ') roles
FROM users
JOIN users_roles ON users.user_ID = users_roles.user_ID
JOIN roles ON users_roles.role_ID= users_roles.role_ID
GROUP BY users.user_ID

The users_roles table:

+----------+---------+
|  user_ID | role_ID |
+----------+---------+
|        1 |   1     |
+----------+---------+
|        2 |   1     |
+----------+---------+
|        2 |   2     |
+----------+---------+
|        2 |   3     |
+----------+---------+
|        1 |   3     |
+----------+---------+

The roles table:

+----------+------------+
|  role_ID | short_name |
+----------+------------+
|        1 |   Admin    |
+----------+------------+
|        2 |   Super    |
+----------+------------+
|        3 |   Other    |
+----------+------------+
  • 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-01T17:56:17+00:00Added an answer on June 1, 2026 at 5:56 pm

    You could try:

    SELECT users.*,
            SUM(overtime_list.shift_length) AS overtime_total,
            (SELECT GROUP_CONCAT(roles.short_name) FROM users_roles 
             INNER JOIN roles ON user_roles.role_ID = roles.role_ID
             WHERE users.user_ID = users_roles.user_ID) AS roles
        FROM availability_list
        INNER JOIN users
            ON users.user_ID = availability_list.user_ID
        INNER JOIN stations
            ON users.station_ID = stations.station_ID
        INNER JOIN overtime_list
            ON overtime_list.user_ID = users.user_ID
            AND overtime_list.date >= '$totalovertimedays'
        WHERE availability_list.date = '$date'
        AND availability_list.type = '$type'
        GROUP BY users.user_ID
        ORDER BY overtime_total ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my base query select distinct a.projects , case when(billing_fy!=0) then(select round(((sum(cost_project)/(sum(billing_fy)/((10/12)*365)))),2) from
I have this query SELECT semester, COUNT(id) AS total, RIGHT(RTRIM(semester), 4) AS year FROM
For this query SELECT min(date) min_date FROM order_products group by order_id min_date ignores the
keyword = house SELECT * FROM products WHERE description LIKE '%house%' This query also
Why does this produce an object? $sql = $this->db->query( SELECT 'product_id' FROM . DB_PREFIX
this query SELECT * FROM tblContracts LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id INNER
I have this query: SELECT Auctions.ID FROM Auctions INNER JOIN Products ON Auctions.ProductID =
The following query: SELECT Assets.Id, Assets.Description FROM Assets WHERE CaseNumber = 1265 produces 29
I have a query which produces a list of orders like this: Invoice Description
I am using this query to produce a blog archive menu, like so: SELECT

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.