choosing WHERE by index

S

Senna

Hi all,
With a ORDER BY I can run this expression

<code>
SELECT a_id, a_name FROM aaa ORDER BY 2 DESC
</code>

But how can I do the same with WHERE, like below. Is it
possible?

<code>
SELECT a_id, a_name FROM aaa WHERE 2 = 'Hmm'
</code>
 
D

Douglas J. Steele

You can't. You must include the name of the field.

SELECT a_id, a_name FROM aaa WHERE a_name = 'Hmm'
 
A

Allen Browne

Is this a serious question?

Ordering by a literal value makes no sense.

Selecting where a literal number equals a string is not even syntatically
consistent.
 
J

Joan Wild

Allen said:
Is this a serious question?

Ordering by a literal value makes no sense.

It's actually ordering by the third column. Try it in Northwind

SELECT * FROM Customers ORDER BY 3;

That will order by the contactname.
 
A

Allen Browne

Thanks, Joan.

Had completely forgotten that you could use the field ordinal in that way.

Apologies, Senna. Doug's answer is correct.
 
S

Senna

Thanks for your answers.
Went a other way for it to work out.

Thought the idea would be a good so that you dynamically
could choose which column the WHERE clause should effect,
like.
SELECT a_id, a_name FROM aaa WHERE @column = @value


Best regards / Senna
 
Top