[sql] 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.

This question is related to sql

The answer is


An aggregate function requires a GROUP BY in standard SQL

This is "Get minimum date per title" in plain language

SELECT title, MIN(date) FROM table GROUP BY title

Most RDBMS and the standard require that column is either in the GROUP BY or in a functions (MIN, COUNT etc): MySQL is the notable exception with some extensions that give unpredictable behaviour


To get the titles for dates greater than a week ago today, use this:

SELECT title, MIN(date_key_no) AS intro_date FROM table HAVING MIN(date_key_no)>= TO_NUMBER(TO_CHAR(SysDate, 'YYYYMMDD')) - 7


SELECT  MIN(Date)  AS Date  FROM tbl_Employee /*To get First date Of Employee*/