Svinjica
Svinjica

Reputation: 2519

Selecting values by last date

I have table with several entries for one point, is it possible to show only last entry for each point?

Example

points |  date
A1       2016-02-12
A1       2016-02-15
A1       2016-03-12
B1       2016-01-11
B1       2016-03-15
B1       2015-09-28
C1       2016-01-28
C2       2016-03-03
D1       2015-12-12
D1       2016-01-12
E2       Null
E3       Null 
F1       Null 

I want to get something like this, without ignoring Null values.

points | date
A1       12.03.2016.
B1       12.03.2016.
C1       03.03.2016.
D1       12.01.2016.
E2       Null
E3       Null 
F1       Null 

I edited question because I tried group by and it didn't work for me( I forgot to mention before) It showed only entries with date, and I need points with null value as well Something like this:

    A1       12.03.2016.
    B1       12.03.2016.
    C1       03.03.2016.
    D1       12.01.2016.

Upvotes: 0

Views: 26

Answers (1)

Vipin Jain
Vipin Jain

Reputation: 3756

You can get by using MAX FUNTION

SELECT points,MAX(date) 
FROM table_name
GROUP BY points;

if you want to change date format you can use DATE_FORMAT function

Upvotes: 1

Related Questions