Example (standard-style syntax). Verify supported keywords in your database.
SELECT name, COUNT(*) AS total FROM users WHERE active = TRUE GROUP BY name HAVING COUNT(*) > 1 ORDER BY total DESC;Query rows from one or more tables.
SELECT [DISTINCT] column_list FROM table_name [WHERE condition] [GROUP BY columns] [HAVING condition] [ORDER BY columns] [LIMIT count];Example (standard-style syntax). Verify supported keywords in your database.
SELECT name, COUNT(*) AS total FROM users WHERE active = TRUE GROUP BY name HAVING COUNT(*) > 1 ORDER BY total DESC;SQLite-oriented variant; dialect behaviour may differ.
SELECT name, COUNT(*) AS total FROM users WHERE active = 1 GROUP BY name HAVING COUNT(*) > 1 ORDER BY total DESC;| Option / clause | Description |
|---|---|
DISTINCT | Remove duplicate result rows. |
WHERE | Filter rows before grouping. |
GROUP BY / HAVING | Aggregate rows and filter grouped results. |
ORDER BY | Sort the result set. |
LIMIT / OFFSET / FETCH | Set a row limit and offset; dialect syntax varies. |
Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.