3
I need to limit the number of occurrences of each type of material I have in my database.
Follow the query below with what I want to do:
SELECT TOP 10 ID, NOME, TIPO FROM TB_MATERIAIS WHERE TIPO = 1
SELECT TOP 10 ID, NOME, TIPO FROM TB_MATERIAIS WHERE TIPO = 2
SELECT TOP 10 ID, NOME, TIPO FROM TB_MATERIAIS WHERE TIPO = 3
SELECT TOP 10 ID, NOME, TIPO FROM TB_MATERIAIS WHERE TIPO = 4
As you can see, I want the first 10 occurrences of each type of material in my query.
But I need to make it a single query. In this case, I need the first 10 occurrences of each type in the same query.
How can I do this? With CASE WHEN it is possible to make a counter for each type of material? I even did some tests, but without success. I guess my logic isn’t working on that question.
Unfortunately I could not extract an answer from the question below
the guys are fixed?
– novic
yes, there are only those 4.
– DiChrist
the solution of Sorack, should solve your problem thanks.
– novic