Show latest results however with ASC ordering in PHP

3

I would like to show the last 10 results found in a table, but with ASC ordering. I'm using the following:

$listarResultados = $pdo->prepare("SELECT * FROM teste WHERE categoria = 'cateste' ORDER BY id ASC LIMIT 10");
$listarResultados ->execute();

It turns out that this select returns me the first 10 results, and I want to list the last 10 but in ASC order. What is the right way to do this?

    
asked by anonymous 15.08.2015 / 23:15

1 answer

4

Use a sub-query:

SELECT *
FROM (SELECT * FROM teste WHERE categoria = 'cateste' ORDER BY id DESC LIMIT 10) S
ORDER BY id ASC
    
15.08.2015 / 23:42