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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:34:24+00:00 2026-06-15T12:34:24+00:00

I have a problem regarding joining tables with group_concat. Here are the details. table_orders:

  • 0

I have a problem regarding joining tables with group_concat. Here are the details.

table_orders:

item_cd    order_id    descs            quantity    status   seq_no
 1           100       coca-cola         2           A         232
 2           100       pizza             1           A         233  
 3           101       cheeseburger      5           A         234
 4           102       pepsi             4           A         235
 4           

table_instructions:

item_cd    instruction  
  3         more cheese  
  3         less vegetable  

cancelled_item_table:

 quantity  seq_no  
    1       234
    1       234
    1       235  

Now what I want to achieve is like this:

item_cd    descs         quantity    instructions                   cancelled_item  
 1         coca-cola         2       -                                  -
 2         pizza             1       -                                  -
 3         cheeseburger      2       more cheese, less vegetable       1,1
 4         pepsi             4       -                                  1  

This is my current query:

SELECT 
    ord.item_cd, 
    ord.order_id, 
    ord.descs, 
    ord.quantity,  
    GROUP_CONCAT(x.quantity) as cancelled,  
    GROUP_CONCAT(i.instruction) as instruct  
FROM table_orders ord
LEFT JOIN cancelled_item_table x ON ord.seq_no = x.seq_no
LEFT JOIN table_instructions i ON ord.item_cd = i.item_cd    
WHERE ord.status = 'A'
GROUP BY ord.order_id

and here is the output:

item_cd    descs         quantity    instructions                   cancelled_item  
 1         coca-cola         2       -                                  1
 2         pizza             1       -                                  1
 3         cheeseburger      2       more cheese, more cheese,  
                                     less vegetable, less vegetable    1,1,1,1
 4         pepsi             4       -                                  1  

If you notice, cheeseburger has 2 cancelled item and 2 instruction, but the output is 4, looks like it’s multiplying.

  • 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-15T12:34:25+00:00Added an answer on June 15, 2026 at 12:34 pm

    Since the join with cancelled_item_table multiplies rows, you have to join to an already grouped subquery, like this:

    SELECT
      ord.item_cd,
      ord.order_id,
      ord.descs,
      ord.quantity - coalesce(x.tot,0) as quantity,
      GROUP_CONCAT(i.instruction) as instruct,
      x.cancelled
    FROM
      table_orders ord LEFT JOIN table_instructions i
      ON ord.item_cd = i.item_cd LEFT JOIN
      (select seq_no, count(*) as tot, GROUP_CONCAT(quantity) as cancelled
       from cancelled_item_table
       group by seq_no) x ON ord.seq_no = x.seq_no
    WHERE ord.status = 'A'
    GROUP BY ord.item_cd, ord.order_id, ord.descs, quantity
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple problem regarding a loop in a Rails controller. Here's the
I have a simple question regarding the dichotomy of joining two tables vs using
I have a problem regarding mysql. I have few tables like course , papers
I have a problem regarding StartUp Url in WPF. I have a LoginView.xaml and
I have a problem regarding the datediff MYSQL function, I can use it and
I have a problem regarding the ksoap2. My problem is that the project used
I have a problem regarding Android App. I have created an application that download
Description: I have a problem regarding DataGridView . I need to show a Client_Name
I have the following code, and i have a problem regarding changing the ringtone
Good day everyone! I have a problem regarding my date. It needs to be

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.