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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:53:42+00:00 2026-05-30T16:53:42+00:00

I asked a question yesterday on how to pull out multiple results into one

  • 0

I asked a question yesterday on how to pull out multiple results into one field and was given the answer GROUP_CONTACT().

I’ve put this into my code and it works fine. I need to do this for two fields and thus I have now started to use it twice in the same sql statement. Unfortunately, it’s pulling back an empty list for the second field with commas and I’m not too sure why.

Here is my sample product data:

pid || prod
1   || top
2   || sweater

Here is my sample stock data (some stock doesn’t have two sizes e.g. waist and chest):

sid || size1 || size2 || pid
1   || M     ||       || 1
2   || L     ||       || 1
3   || XL    ||       || 1
4   || L     ||       || 2
5   || XL    ||       || 2

Here is my code:

SELECT p.id, GROUP_CONCAT(s.size1) size1, GROUP_CONCAT(s.size2) size2, p.prod
FROM products p JOIN stock s ON s.prodid = p.id

This is what it should bring out:

pid || size1  || size2 || prod
1   || M,L,XL ||       || top
2   || L,XL   ||       || sweater

This is what it is actually bringing out:

pid || size1  || size2 || prod
1   || M,L,XL || ,,    || top
2   || L,XL   || ,     || sweater

I’ve checked to see if there is a space or anything in size2 and there is nothing in there.

I did this query and the product came back as I expected:

SELECT size1, size2 FROM stock WHERE pid = 1 AND size2 = ""

When I did this query, nothing came back:

SELECT size1, size2 FROM stock WHERE pid = 1 AND size2 IS NULL

I know GROUP_CONCAT() will ignore NULL results but I need to do something to stop GROUP_CONTACT() from showing an empty comma delimited list when it is just "" rather than NULL.

  • 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-30T16:53:43+00:00Added an answer on May 30, 2026 at 4:53 pm
    SELECT p.id, GROUP_CONCAT(s.size1) size1, 
    GROUP_CONCAT(if (s.size2 ='', null, s.size2)) as size2, p.prod 
    FROM products p JOIN stock s ON s.prodid = p.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question yesterday got a pretty good answer but can't figure out
I asked this question yesterday, looking if more people can help me out. I
I asked this question yesterday and it turned out to be a Maven issue.
I asked a question yesterday which got answers but didnt answer the main point.
I asked this question yesterday, and at the time it was just what I
i asked this question yesterday but it doesnt seem to have asked properly so
I asked a question about different testing frameworks yesterday. This question can be found
Yesterday in my interview I was asked this question. (At that time I was
I asked a similar question like this yesterday but after waiting for ever I
As an answer to a question I asked yesterday ( New Core Data entity

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.