Selecting the Max and Min records in one MySQL command

Is this what you are looking for?

select id, name from customers where id = ( select max(id) from customers )
union all
select id, name from customers where id = ( select min(id) from customers )

Now I have tested this type of query on a MySQL database I have access, and it works. My query:

SELECT nome, livello
FROM personaggi
WHERE livello = (
SELECT max( livello )
FROM personaggi ) 

SELECT MIN(id), MAX(id) FROM tabla

EDIT: If you need to retrive the values of the row you can do this:

SELECT *
FROM   TABLA AS a, (SELECT MIN(id) AS mini,
                            MAX(id) AS maxi
                     FROM   TABLA) AS m
WHERE  m.maxi = a.id
       OR m.mini = a.id;

Tags:

Mysql