Can MySQL output data into groups with a group label?

I’m fairy new to MySQL and I want to pull data from my database and dump into a spreadsheet.

Is there a way to run a query that would output data into groups and display a group name before each grouping?

In example:

If my data had the following columns in my table_of_stuff:

items_column (apple, orange, banana, lettuce, tomatoes, onions)
itemType_column (FRUIT, VEGETABLE)

I want to run a query like this:

SELECT * FROM table_of_stuff ORDER BY itemType_column;

However I want the ability to display group headings in data output like this:

FRUIT
apple
banana
orange
VEGETABLE
lettuce
onions
tomatoes

Is this something that can be done in MySQL?

You can do nearly everything in MySQL but I don’t understand the use case.
Normally the spreadsheet should also contain two columns with type and value. Otherwise you are not able to filter, search or work with it in any way.
So what is the final approach?

How are you accessing the database, is it PDO?
It’s just I know how to do this with PDO using the FETCH_GROUP fetch mode.

I have database of collectable miniatures for table top gaming. These miniatures are associated with “sets” (each set may have 1 to 70 minis), and there are 5 different product lines/brands of sets.

Users of the online database have requested a spreadsheet for which they can use as a checklist.

I don’t actually want to create the spreadsheet for them – I am very experienced with Excel and could do this fairly easily, but I really just don’t have the time.

Using PHPMyAdmin, I just want to run a query to grab this info, and then export it as a CSV so I can copy and paste that info into a Google spreadsheet.

The quick way, is just to have each row of data output the set name. However, rather than create a sheet with formulas to organize the sheet into miniatures grouped by sets from the CSV data, I thought there might be a way to output into grouped categories with a SQL query.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.