Getting a query from a query

#1

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.

0 Likes

#2

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'
2 Likes

#3

It worked :slight_smile:

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

Have a good day!

0 Likes