Sql server
i have two table table1 and table 2 i want to display all data of table2 but sorting order like table 1
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khan Abrar AhmedRank #778 · 3K reputationPosted May 12, 2014, 4:49 AM EDT
you can try like this,
DECLARE @tb1 AS TABLE (id INT, valueDESC VARCHAR(32))
DECLARE @tbOrder AS TABLE (id INT)
INSERT INTO @tb1
values (1,'a'),(3,'b'),(4,'c'),(2,'d')
INSERT INTO @tbOrder
values (1),(2),(3),(4)
SELECT a1.* FROM @tb1 AS a1
JOIN @tbOrder AS [to] ON [to].id = a1.id
ORDER BY [to].id