PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I group the results of a mysql query?


If you want to group the results by a particular field value rather than listing all results individually, then you use the GROUP BY keyword.

Here is how the query might look:

SELECT columns FROM Table WHERE clause GROUP BY column ORDER BY column

Common mistakes are to apply the GROUP BY either before the WHERE clause or after the ORDER BY - make sure you get it right.

Also remember that you are returning aggregate data rather than every result as an individual row, therefore it can take a little bit of careful thinking as to when you should use GROUP BY and a realisation of what will be returned when you do.

More mysql PHP Questions

How do I return a random row from the database?
How do I delete a row from a table?
How do I limit the number of rows returned?
How do I connect to mySQL from PHP?
How do I find the number of rows affected by a query?