We came across a situation in which we had to sort a table (limited by a WHERE clause) and order this again by another column. We thought this was easy to do using a subselect but SQL Server refuses to sort views. After some experimenting we came up with the following query:
SELECT * FROM
(
SELECT TOP 5 topicKnowledgeID, topicID, rating, tblTopicKnowledge.date, username
FROM dbo.tblTopicKnowledge
WHERE (topicID = @topicID AND username = @username)
ORDER BY topicKnowledgeID DESC
) AS sortedTopicKnowledgeTable
ORDER BY topicKnowledgeID ASC
Great succes!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment