-1

MySql Database

I am not sure if i could do this . I have a table with values as below

  |invoicenumber|item_descreption| 
  |      1      |     boots      |
  |      1      |     hats       |

I need to make select statment to return only one value from the above tables the expected result should be

  | allItemsInTheInvoice |
  |  boots , hats        |

Can someone help me to do that ?

Shadow
  • 33,525
  • 10
  • 51
  • 64
Ahmed Shahin
  • 74
  • 1
  • 8

1 Answers1

1

You can try to use GROUP_CONCAT

Query 1:

SELECT GROUP_CONCAT(item_descreption) as allItemsInTheInvoice
FROM T 

Results:

| allItemsInTheInvoice |
|----------------------|
|           boots,hats |

if you want to select invoicenumber need to add in group by

SELECT GROUP_CONCAT(item_descreption) as allItemsInTheInvoice ,invoicenumber
FROM T 
GROUP BY invoicenumber 
D-Shih
  • 44,943
  • 6
  • 31
  • 51
  • I guess _allItemsInTheInvoice_ means that OP wants to GROUP BY invoicenumber. – jarlh Nov 22 '21 at 13:00
  • Next time please double check if a question has already been answered here on SO in case a question is such a straightforward one! – Shadow Nov 22 '21 at 13:03