Getting a query from a query

Good morning guys.

I’m trying to gather information about a table in my database.

The information of the database is the following:

I’m trying to gather a count of “NEXT MAX” of the last 10 rows of my table.

my query is:
SELECT COUNT(*)
FROM prueba3
WHERE modelo = “NEXT MAX”
ORDER BY id DESC
LIMIT 10

The result im getting is 3, i want to get the result 2.

Is there a direct way to do this using a simple Query? if not, Is there a way doing a query over a query?

Thanks in advance for the help.

You can use a subquery to gather your 10 rows:

SELECT count(*)
FROM (SELECT * FROM prueba3
		ORDER BY id DESC
		LIMIT 10
	) AS sample
WHERE modelo = 'NEXT MAX'
3 Likes

It worked :slight_smile:

Thank you so much for the help, i really appreciate it.

Have a good day!