Add sequence number to query results

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to run a SELECT query based on a column and include a sequence column
in the results. Does anyone know how to do this?
e.g. if my table has values 200,150,700,500,300
It should return:
1 150
2 200
3 300
4 500
5 700
 
Try this --
SELECT (SELECT COUNT(*)
FROM [YourTable-4] T1
WHERE T1.Column1 <= T.Column1) AS Sequence, T.Column1
FROM [YourTable-4] AS T;

When you run it the first time the sequence may be out of order. Click in
the column then click the A-Z icon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top