choosing WHERE by index

  • Thread starter Thread starter Senna
  • Start date Start date
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>
 
You can't. You must include the name of the field.

SELECT a_id, a_name FROM aaa WHERE a_name = 'Hmm'
 
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.
 
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.
 
Thanks, Joan.

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

Apologies, Senna. Doug's answer is correct.
 
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
 
Back
Top