-3

Here is mysql table

version filename     fileid time(epoch)
1   abc      NULL    123456
2   abc      100     234568
3   abc      100     344568
4   abc      100     445678
5   abc      100     554568

Required output

version  filename     fileid    time(epoch)
5        abc          100       554568

Tried

SELECT MAX(VESRION), MAX(time), filename, fileid
FROM table filename, fileid

Getting this but not want

version  filename     fileid    time(epoch)
5        abc          100       554568
5        abc          NULL      123456

Anyone help ?

Thanks !!

3 Answers3

0

Just add a WHERE clause to the query. Like this:

SELECT MAX(VESRION), MAX(time), filename, fileid
FROM table filename, fileid
WHERE fileid is not null
Paul Andrew
  • 3,233
  • 2
  • 17
  • 37
0

You can try with a where clause

SELECT MAX(VESRION), MAX(time), filename, fileid FROM table filename, fileid where fileid is not null

MySQL SELECT only not null values

Community
  • 1
  • 1
Liz Lemon
  • 81
  • 1
  • 2
  • What if the row having Null and also falls in same group having MAX of version or time ? – Ashish Jangra Aug 19 '16 at 07:14
  • You can "pre-filter" the query with the is not null removing this rows that you are not interested in, and apply the having clause to that query after – Liz Lemon Aug 19 '16 at 07:20
0

Use limit with order by.

Query

select * from your_table_name
order by version desc limit 1;
Ullas
  • 11,450
  • 4
  • 33
  • 50