Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order by (number) 1

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
Why does this not work?

Select * from mytable order by 0

Where 0 is the number of the field in the query.

Thanks
 
SELECT * FROM myTable ORDER BY [FieldName];

You can sort records by the field names

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
I know that, but when I do not know the fieldname and I know the field number, what do I do.
Thanks
 
And this ?
Select * from mytable order by [!]1[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

'ORDER BY 0' does not work, where 'ORDER BY 1' (or 2 or 5) works (as long as you point to exsisting field in a recordset) because fields in recordset start with 1, and not 0 as some would expect. It is pretty handy when - as you said - you may not know the name of the field, but you do know its position. It also comes handy with UNIONs statements.

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top