Back to Developer Roadmap

Select Non Grouped Column

src/data/question-groups/sql-queries/content/select-non-grouped-column.md

4.0667 B
Original Source

If you SELECT a column not in the GROUP BY clause, it will throw an error stating that the column must be in the GROUP BY clause or in an aggregate function. Let's use the table below as an illustration.

firstNamelastNamephoneNumber
JohnDoe+23410910
JackRay+23410911
IreneRotherdam+23410911

If you run the query below against the database:

sql
SELECT firstName, phoneNumber FROM phoneNumbers
GROUP BY phoneNumber

The result will be an error because firstName is not in the GROUP BY clause and not using an aggregate function.