I am trying to pull back the top five instances of certain records loaded into a table. It is important to note that I am trying to get my results out of the same table and I think there is a problem that I can't quite figure out related to the fact that this is one table. Here is the example of my query:
Select * From (
Select Top 5 JobID From Jobs Where JobTypeID = 1 Order By JobID DESC
UNION ALL
Select Top 5 JobID From Jobs Where JobTypeID = 2 Order By JobID DESC
UNION ALL
Select Top 5 JobID From Jobs Where JobTypeID = 3 Order By JobID DESC
UNION ALL
Select Top 5 JobID From Jobs Where JobTypeID = 4 Order By JobID DESC
UNION ALL
Select Top 5 JobID From Jobs Where JobTypeID = 5 Order By JobID DESC
UNION ALL
Select Top 5 JobID From Jobs Where JobTypeID = 6 Order By JobID DESC
) As UnionTable
When I run this is SQL Server I only get 9 records when I know in fact that there should be 30. How can I make sure that I pull back all of the correct records? Do I need to use a Group By clause in each subquery?