0

I am working on an API to return a list of venues.

SELECT 
    `sample`.Fascia AS 'Fascia',
    `sample`.Category AS 'Category'
FROM
    `sample`
WHERE 
    `sample`.`PostCode` LIKE '%SW1%'

and this returns a list of venues.

Fascia      | Category
------------+-------------
Sainsbury's | Supermarkets
Waitrose    | Supermarkets
99p Store   | Hardware
T K Max     | Clothing

How would I modify the query to group the categories together and create an abstract column that lists these venues as a comma list. So something like this

Category      | Grouped Venues
--------------+------------------------
Supermarkets  | Sainsbury's, Waitrose
Hardware      | 99p Store
Clothing      | T K Max

1 Answer 1

1

use Group_concat:

        SELECT 
        Group_concat(`sample`.Fascia) AS 'Grouped Venues',
        `sample`.Category AS 'Category'
        FROM
        `sample`
        WHERE `sample`.`PostCode` LIKE '%SW1%'
        Group by `sample`.Category
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.