Question: I'm trying to create a query to return the file with the max version, independent of the value of the server. How could I do that?

actual table data:

```
server    filename    v4    date
local     code1.zip   41    0000-00-00
remote    code1.zip   39    0000-00-00
local     code1.zip   28    0000-00-00
remote    code1.zip   21    0000-00-00
local     code1.zip   32    0000-00-00
remote    code1.zip   27    0000-00-00

```

the query:

```
SELECT
    server,
    filename,
    max(v4) as v4,
    date
FROM
    table
WHERE
    date ='0000-00-00'

GROUP BY
    filename,
    server,
    date

```

Actual result:

```
server    filename    v4    date
local     code1.zip   41    0000-00-00
remote    code1.zip   39    0000-00-00

```

Expected result:

```
server    filename    v4    date
local     code1.zip   41    0000-00-00

```

EDIT: It's for **MySQL** 

Thanks in advance.

Answer: 
To get the the max version you only have to do:

```
SELECT MAX(version) FROM table 

```

If you also want the filename (if you have another column `id`):

```
SELECT t2.filename, t2.maxver
FROM table t1 INNER JOIN
(SELECT id, MAX(version) maxver 
FROM table 
GROUP BY id) t2 ON t1.id=t2.id
ORDER BY t2.maxver DESC
LIMIT 1

```

If you also want the filename (if you haven't another column `id`, use `filename`):

```
SELECT t2.filename, t2.maxver 
FROM table t1 INNER JOIN
     (SELECT filename, MAX(version) maxver 
      FROM table 
      GROUP BY filename) t2 ON t1.filename=t2.filename
      WHERE t2.maxver = (SELECT MAX(version) FROM table)

```

There are many ways to do it.
You could use this query:

```
Select Top 1 *
From table
Where v4 = (
SELECT
    max(v4) as v4,
FROM
    table
WHERE
    date ='0000-00-00'

GROUP BY
    v4
)

```