By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,662 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,662 IT Pros & Developers. It's quick & easy.

How do I use ORDER BY with a custom column name?

P: 2
I'm using Access 2000 and I'm trying to do something like this:

SELECT Employee, Status as ss
FROM data

This query doesn't run since it appears that Access doesn't recognize "ss" as a valid field in the ORDER BY clause. How can I get this effect?

BTW, it won't do for me to use "ORDER BY Status". This is a very simplified version of the actual query I'm trying to use in my program. In the full problem I have columns in two joined tables with the same name. The part of my code that creates the order by part of the query doesn't have knowledge of which field to use for sorting so I wanted to use a generic name there and specify the correct column using the "as" construct. I've used this trick many times while working with MySql databases. I was hoping that I could do the same thing with Access.

Any help will be appreciated.

May 19 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,923
[size=3][font=Times New Roman][color=black]ORDER BY can work with an alias column if you use "order by N" (N - selected item number).

So, the code below should work:

[/color]SELECT Employee, Status as ss
FROM data
[color=black]ORDER BY 2 'the second item in your selection list[/color][/font][/size]
May 19 '07 #2

P: 2
Excellent. Thanks.

May 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.