sql server
i have two table table1 and table 2 i want to display all data of table2 but sorting order like table 1
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khan Abrar AhmedPosted May 12, 2014, 8:49 AM
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