-2
SELECT Distinct ', '+ (select text from dbo.codelists 
where id = LoadReferenceTypeId), ': ' +  ReferenceValue FROM dbo.LoadReferences 
WHERE LoadId = 89 and EndDate IS NULL 
Vasanth R
  • 172
  • 1
  • 1
  • 14
  • 1
    looks like `sql-server`. Please remove unwanted tags. And be clear on what you are trying to do – Ullas Sep 20 '17 at 12:04
  • Possible duplicate of [SQL multiple column ordering](https://stackoverflow.com/questions/2051162/sql-multiple-column-ordering) – Skami Sep 20 '17 at 12:04
  • You should read about joins and use them instead of subqueries in your columns. Then use some aliases so you know which table each column came from. – Sean Lange Sep 20 '17 at 13:15

1 Answers1

0

You need to add order by at the end of SQL statement.

Try:

SELECT Distinct ', '+ 
(
  select text from dbo.codelists 
  WHERE id = LoadReferenceTypeId
)
, ': ' +  ReferenceValue 
FROM dbo.LoadReferences 
WHERE LoadId = 89 and EndDate IS NULL
ORDER BY column_name DESC;
jarlh
  • 42,561
  • 8
  • 45
  • 63