You will see I need to send to ask for an amount n of questions, where that amount is given by a parameter. The query is already functional and sends them to the parameter randomly.
What happens now is that it shows questions that are repeated, and should show unique questions, so I was seeing some things of
SELECT DISTINCT but I'm not sure how to implement it since there is already a
SELECT TOP sentence.
Here is the query, it's done in
SQL Server 2012 :
ALTER PROCEDURE [dbo].[spListarPreguntasPorTema] (@prmLimite int, @prmCodTema int ) AS BEGIN SELECT TOP (@prmLimite) p.cod_pregunta, p.pregunta FROM dbo.pregunta AS p INNER JOIN dbo.tema AS t ON p.cod_tema = @prmCodTema AND @prmLimite = t.no_preguntas ORDER BY NEWID() END