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.
How can I do this? With CASE WHEN is it possible to make a counter for each type of material? I even did some testing, but without success. I think my logic is not working out.
Unfortunately I could not extract an answer from the question below