I have a table with multiple questions from different domains, example: Math, Physics, Chemistry and I have a query to select questions from that table and write them in a new table. What I have is selecting random questions from table with:
BEGIN INSERT INTO tblTestDetailSSM (IdIntrebare, IdUserTest) SELECT TOP 10 ti.IdIntrebare AS IdIntrebare, @IdUserTest FROM (SELECT TOP 100 * FROM tblIntrebare ORDER BY NEWID()) ti JOIN tblProcedura tp ON ti.IdProcedura = tp.IdProcedura WHERE tp.Complexitate = 'GENERAL' AND tp.Specialitate = 'SSM'; END
where tp.Specialitate = 'SSM' includes all domains. I want to be able to select random questions, one from each domain and add it to tblTestDetailSSM. So that means multiple select query FROM which to select top 10. How do I do that?