Skip to content
Advertisement

SQL grammar for SELECT MIN(DATE)

I have a table with structure: id(INT PK), title(VARCHAR), date(DATE)

How do I select all distinct titles with their earliest date?

Apparently, SELECT DISTINCT title, MIN(date) FROM table doesn’t work.

Advertisement

Answer

You need to use GROUP BY instead of DISTINCT if you want to use aggregation functions.

SELECT title, MIN(date)
FROM table
GROUP BY title
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement