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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:44:48+00:00 2026-06-05T22:44:48+00:00

I have a query on the db of a shopping cart that involves a

  • 0

I have a query on the db of a shopping cart that involves a few outer joins that returns something like this (heavily simplified):

Orderid |   Customer Name | Product | Image
 1      |      John       |  Prod1  | x.jpg
 1      |      John       |  Prod2  | e.jpg
 2      |      Paul       |  Prod3  | r.jpg
 3      |      Ringo      |  Prod1  | x.jpg

I would like the results to come out something like this

Orderid | Customer Name | Product1 | Image1 | Product2 | Image 2
  1     |      John     |   Prod1  |  x.jpg | Prod2    | e.jpg
  2     |      Paul     |   Prod3  |  r.jpg | NULL     | NULL
  3     |      Ringo    |   Prod1  |  x.jpg | NULL     | NULL

Is this possible?

My previous query used a GROUP_CONCAT and had the result as a blob but I didn’t find it useful to work with.

  • 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-05T22:44:50+00:00Added an answer on June 5, 2026 at 10:44 pm

    To reliably get all of the products into a varying number of columns, you would need to use a PIVOT feature as present in DBMSs like SQL Server, Oracle, etc.

    In the case of MySQL, that sort of feature is not available and the best way to generate a CSV straight from the query (as you mentioned in the comments to your question) would be to use GROUP_CONCAT().

    The reason why you had “blob” data in your GROUP_CONCAT() before was because you were trying to concatenate two different data types into the string, and thus the phpMyAdmin was automatically converting it to [BLOB]. You must have been concatenating various integer values(ID’s, prices, etc.) along with string values. What you must do is CAST() the integer values to strings within your GROUP_CONCAT() so that PMA doesn’t convert to blob. More info on CAST().

    Depending on what version of PMA you have, it may or may not convert to [BLOB]. If it does, you could always expand +options and check “Show blob contents” and it will show the expected result.

    Just based on your above example (in addition to product_id to illustrate CAST(), you could do something like:

    SELECT
        order_id,
        customer_name,
    GROUP_CONCAT(CONCAT(CAST(product_id AS CHAR(6)), '|||', product, '|||', image) SEPARATOR ':::') AS order_products
    FROM 
        orders
    GROUP BY
        order_id,
        customer_name
    

    This would give you a result set along the lines of:

    Orderid | Customer Name | order_products 
      1     |      John     |   1|||Prod1|||x.jpg:::2|||Prod2|||e.jpg
      2     |      Paul     |   3|||Prod3|||r.jpg
      3     |      Ringo    |   1|||Prod1|||x.jpg
    

    Then depending on the language you’re using to build your application, you can “explode” the order_products string into arrays. First explode on the delimiter ::: to separate products, then for each product, explode again on the delimiter ||| to separate that product’s details.

    I use those particular delimiters because commas can be present in fields like the title, etc. and you would not want your script to separate the string in the wrong places. This possibility of erroneous separation is one of the major downsides to using GROUP_CONCAT(), so you must decide which delimiters would be best to use based on the unlikelihood that they would be present within the field values.

    Also, watch out for nullable fields when using CONCAT. For example, say for each product that the image field wasn’t required and could contain NULL. If one part of CONCAT() is NULL, then the entire concatted string will become NULL.

    So for whichever field is nullable, you would want to use COALESCE() on the field to prevent NULLs being passed to CONCAT(). (e.g. CONCAT(product, '|||', COALESCE(image, 'NoImage'))

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

Sidebar

Related Questions

I have a shopping cart that continually logs slow queries like this one... #
I have a shopping cart which at this point in time sends items that
I have query to show the table like this: but I want to PIVOT
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have the following raw query which moves items from a shopping cart to
I have this quite long query that should give me some information about shipments,
I have this php script that generate an sql query. However, it needs a
I have this MySQL query. I have database fields with this contents sports,shopping,pool,pc,games shopping,pool,pc,games
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I am using in C# MYsql .I have query that works if I run

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.