I have the following table
MyTable
ID
MessageType
MessageDate
MessageBody
The table is a few million rows but there are only 100 unique MessageType in it.
What I need is a sample of each MessageType (must include at least MessageType and MessageBody), but I can’t do a DISTINCT as that only gets me the MessageType column.
I am thinking something like
SELECT TOP 5 *
FROM MyTable
WHERE MessageType IN (SELECT DISTINCT MessageType FROM MyTable)
I know this doesn’t work as it just me the top 5, but I am not sure how to make SQL loop through this.
Thanks for any help
The Row_Number version
The
CROSS APPLYversion