sql >> Database teknologi >  >> RDS >> Mysql

Forespørgsel sammenkæder alt i én række i stedet for i separate rækker

Du skal tilføje group by klausul

 SELECT o.outfit_id, o.creation_date,
           GROUP_CONCAT(i.manufacturer_product_id ORDER BY i.manufacturer_product_id) as manufacturer_product_ids,
           GROUP_CONCAT(i.manufacturer_product_id ORDER BY i.manufacturer_product_id SEPARATOR ';') as manufacturer_product_ids_sep
    FROM outfits o INNER JOIN
         items_in_outfit io
         ON o.outfit_id = io.outfit_id JOIN
         items i
         ON io.item_id = i.item_id JOIN
         customer c
         ON o.cus_id = c.cus_id 
    WHERE c.driver_id = 2463
    group by o.outfit_id,o.creation_date
    ORDER BY o.creation_date



  1. MYSQL-forespørgsel med variabel som tabelnavn i LEFT JOIN

  2. Hvorfor returnerer MySQL de samme resultater, mens RAND() bruges i SELECT-sætningen?

  3. Revision af PostgreSQL ved hjælp af pgAudit

  4. Sådan benchmarker du PostgreSQL-ydelse