kanabut
kanabut

Reputation: 41

select min max for group data from data table

hi i have data table like this

nickname  date         is_unique
test      01-01-2016   yes 
test      01-02-2016   yes 
test      01-03-2016   yes  
test1     01-01-2016   yes 
test1     01-02-2016   yes 
test1     01-03-2016   yes    

i try to group data for display data like this

nickname  startdate    enddate        is_unique
test      01-01-2016   01-03-2016     yes 
test1     01-01-2016   01-03-2016     yes 

but when i use query code min max it show just 1 column data is "test" it not show data of "test1" here is my sqlquery command

SELECT b.nickname, min(a.date), max(a.date), a.is_unique 
FROM `table1` a 
join `table2` b 
on b.fingerid = a.acno
where a.is_unique = 1

Upvotes: 0

Views: 52

Answers (1)

Anish Chikodi
Anish Chikodi

Reputation: 96

Just add GROUP BY b.nickname in your query, like this,

  SELECT b.nickname, min(a.date), max(a.date), a.is_unique 
        FROM `table1` a 
        join `table2` b 
        on b.fingerid = a.acno
        where a.is_unique = 1
        GROUP BY b.nickname

Upvotes: 2

Related Questions