Ask a Question related to ASP Database, Design and Development.
-
Dragonhunter #1
SQL: is it possible to ORDER BY just the column number?
Hello,
Is it possible to write an SQL statement that references a column number
in a database and not the name of the column?
Instead of this:
set rs = oConn.Execute("SELECT * FROM table ORDER BY ID)
I want to do this:
set rs = oConn.Execute("SELECT * FROM table ORDER BY column(0) )
Is it possible? Thanks!!
Dragonhunter Guest
-
Column order
Hi, I have a problem , I can't retreive the fields in the same order (like in the table) when I use the CFDump I have the column in a alphabetique... -
Auto generate unique order number sequential
Hi: I need help on how to code in a CFFORM an order number. This order number must be auto generated, be unique and sequential. By the way I'm... -
multi column index and order by
Hello, "order by a asc b desc" how can I create an index for this? Mage ---------------------------(end of... -
Column and line order
If I have for example: 3 lines and 3 columns Data grid is constructed like this: first line: first column, second column, third colum second... -
OT. given x digits, how do I calculate the maximum permeations of number order ???
ie, with the numbers 1,2,3 the permeations could be : 123 132 231 213 312 321 I learnt how to do this 20 years ago but now I need it, I... -
Aaron Bertrand - MVP #2
Re: is it possible to ORDER BY just the column number?
> Is it possible to write an SQL statement that references a column number
No. You can use this proprietary syntax, but don't count on it always> in a database and not the name of the column?
working, and of course don't count on it working in other products.
-- order by col1:
SELECT col1, col2 FROM table ORDER BY 1
-- order by col2 DESC:
SELECT col1, col2 FROM table ORDER BY 2 DESC
Are you really going to be using SELECT * in production code???
Aaron Bertrand - MVP Guest
-
Mark Schupp #3
Re: is it possible to ORDER BY just the column number?
ORDER BY <column_number>
is shown as ANSI standard SQL in my old SQL book ("Lan Times Guide to SQL")
so it should work with most SQL DBMSs.
--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
[email]mschupp@ielearning.com[/email]
[url]http://www.ielearning.com[/url]
714.637.9480 x17
"Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
news:%23h6exdvfDHA.1088@TK2MSFTNGP10.phx.gbl...>> > Is it possible to write an SQL statement that references a column number
> > in a database and not the name of the column?
> No. You can use this proprietary syntax, but don't count on it always
> working, and of course don't count on it working in other products.
>
> -- order by col1:
> SELECT col1, col2 FROM table ORDER BY 1
>
> -- order by col2 DESC:
> SELECT col1, col2 FROM table ORDER BY 2 DESC
>
> Are you really going to be using SELECT * in production code???
>
>
Mark Schupp Guest
-
Aaron Bertrand [MVP] #4
Re: is it possible to ORDER BY just the column number?
> ORDER BY <column_number>
SQL")>
> is shown as ANSI standard SQL in my old SQL book ("Lan Times Guide toThat's column number in the SELECT list, not column number in the table. If> so it should work with most SQL DBMSs.
you use SELECT *, you shouldn't be relying on the "order" of the columns to
allow you to order by, IMHO.
Aaron Bertrand [MVP] Guest
-
Jarl Hermansson #5
Re: is it possible to ORDER BY just the column number?
"Mark Schupp" <mschupp@ielearning.com> wrote in message news:<eVyFm8vfDHA.2576@TK2MSFTNGP11.phx.gbl>...
ORDER By <column_number> was valid in SQL-92, but not in SQL-99.> ORDER BY <column_number>
>
> is shown as ANSI standard SQL in my old SQL book ("Lan Times Guide to SQL")
> so it should work with most SQL DBMSs.
In SQL-99, the sort order is specified as:
<sort specification list>::=
<sort specification>[ {<comma><sort specification>}...]
<sort specification>::=
<sort key>[ <ordering specification>] [<null ordering>]
<sort key>::=<value expression>
<ordering specification>::=
ASC
| DESC
<null ordering>::=
NULLS FIRST
| NULLS LAST
As you can see above, a <value expression> has replaced SQL-92's
<column name> or <unsigned number>.
Note that writing "ORDER BY 3" is valid SQL-99 syntax, but doesn't
mean "order by the third column" as in SQL-92. My advice is: DO NOT
USE "order by column-number". Sooner or later the applications using
it just wont work like they used to. (No error code, just strange
behavior.)
Regards,
Jarl
Jarl Hermansson Guest
-
Mark Schupp #6
Re: is it possible to ORDER BY just the column number?
Good point Aaron, I don't use select * so it didn't occur to me.
--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
[email]mschupp2@ielearning.com[/email]
[url]http://www.ielearning.com[/url]
714.637.9480 x17
"Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
news:eTs3bxzfDHA.2248@TK2MSFTNGP09.phx.gbl...If> SQL")> > ORDER BY <column_number>
> >
> > is shown as ANSI standard SQL in my old SQL book ("Lan Times Guide to>> > so it should work with most SQL DBMSs.
> That's column number in the SELECT list, not column number in the table.to> you use SELECT *, you shouldn't be relying on the "order" of the columns> allow you to order by, IMHO.
>
>
Mark Schupp Guest
-
Dragonhunter #7
Re: is it possible to ORDER BY just the column number?
why is select * so evil?
-dragonhunter
Mark Schupp wrote:
> Good point Aaron, I don't use select * so it didn't occur to me.
>
> --
> Mark Schupp
> --
> Head of Development
> Integrity eLearning
> Online Learning Solutions Provider
> [email]mschupp2@ielearning.com[/email]
> [url]http://www.ielearning.com[/url]
> 714.637.9480 x17
>
> "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
> news:eTs3bxzfDHA.2248@TK2MSFTNGP09.phx.gbl...> If> > SQL")> > > ORDER BY <column_number>
> > >
> > > is shown as ANSI standard SQL in my old SQL book ("Lan Times Guide to> >> > > so it should work with most SQL DBMSs.
> > That's column number in the SELECT list, not column number in the table.> to> > you use SELECT *, you shouldn't be relying on the "order" of the columns> > allow you to order by, IMHO.
> >
> >Dragonhunter Guest
-
Ray at #8
Re: is it possible to ORDER BY just the column number?
"Dragonhunter" <dragonhunter97@yahoo.com> wrote in message
news:3F70A0E2.142BFEC4@yahoo.com...[url]http://www.aspfaq.com/2096[/url]> why is select * so evil?
Ray at work
Ray at Guest
-
Aaron Bertrand - MVP #9
Re: is it possible to ORDER BY just the column number?
[url]http://www.aspfaq.com/2096[/url]
> why is select * so evil?
Aaron Bertrand - MVP Guest
-
Bob Barrows #10
Re: is it possible to ORDER BY just the column number?
Dragonhunter wrote:
1. It practically guarantees that you will pull data across the wire that> why is select * so evil?
>
> -dragonhunter
>
you don't really need, especially if your query involves joins.
2. It can cause problems in your code if new columns are added to your
tables.
3. You can't control the order in which the columns are retrieved.
Simply put, it's a bad, lazy habit. Selstar should be reserved for ad hoc
one-off queries, say in Query Analyzer, not production code.
Bob Barrows
Bob Barrows Guest



Reply With Quote

