How Do You Group Rows With GROUP BY in MySQL?
GROUP BY collapses rows into groups so aggregates run per group. Learn multi-column grouping, the ONLY_FULL_GROUP_BY rule, ordering and WITH ROLLUP totals.
47 posts about MySQL: questions with answers, tutorials and articles, newest first.
GROUP BY collapses rows into groups so aggregates run per group. Learn multi-column grouping, the ONLY_FULL_GROUP_BY rule, ordering and WITH ROLLUP totals.
COUNT, SUM, AVG, MIN and MAX summarise many rows into one value. See each function with examples, how NULL affects them and how to combine them with GROUP BY.
NULL is unknown, not zero or empty. Learn IS NULL, the null-safe operator, COALESCE, IFNULL and how NULL affects filters, sorting and aggregates.
SELECT DISTINCT returns each unique value or row once. Learn multi-column DISTINCT, NULL handling, COUNT(DISTINCT) and how it differs from GROUP BY.
MySQL LIMIT caps the rows a query returns and OFFSET skips rows first. Learn pagination, the comma form, and why deep offsets are slow.
Sort MySQL results with ORDER BY using ASC, DESC, several columns, aliases and expressions. Includes NULL ordering, FIELD() and LIMIT with indexes.
Search text in MySQL with LIKE and the % and _ wildcards. Learn escaping, case sensitivity, NOT LIKE and why a leading % makes queries slow.
Use IN and BETWEEN in MySQL to match lists and ranges. Covers NOT IN with NULL, inclusive bounds and the safe way to filter DATETIME columns.
Combine conditions with AND, OR and NOT in MySQL. Learn operator precedence, why parentheses matter and how NULL values change the result.
Use the MySQL WHERE clause to keep only matching rows. Covers comparison operators, text and date filters, IS NULL and mistakes that cause bad updates.
Export MySQL query results to a CSV file with INTO OUTFILE, the mysql client or MySQL Shell, including headers, NULL values and the secure_file_priv limit.
Step-by-step guide to creating a MySQL database and user in cPanel, granting privileges and connecting WordPress or PHP code.
Bulk-import CSV files into MySQL with LOAD DATA INFILE. Covers separators, headers, LOCAL, column conversion and common errors.
Copy rows from one table to another with a single statement. Covers column mapping, aggregates, archiving, duplicates and batching.
INSERT IGNORE skips duplicate-key rows and turns some errors into warnings. Learn how it works, what it hides and when to use something else.
Upsert rows in one statement: insert, or update when a unique key already exists. Covers row aliases, affected counts and pitfalls.
Remove rows with DELETE FROM ... WHERE. Covers batches with LIMIT, foreign keys, joins, TRUNCATE versus DROP and safe deleting.
Change existing rows with UPDATE ... SET ... WHERE. Covers expressions, multi-column updates, joins, transactions and the safe-updates habit.
SELECT reads rows from a table. Learn to pick columns, filter with WHERE, sort with ORDER BY, page with LIMIT and avoid common beginner mistakes.
List several value groups after one VALUES keyword to add many rows in a single statement. Covers batch size, duplicates and LOAD DATA for large files.