Re: 1--1

From: Kiuhnm Mnhuik <gandalf23_at_mail.com>
Date: Wed, 21 Jan 2015 09:11:07 -0800 (PST)
Message-ID: <b6df893c-eade-4e5a-a438-791ebd54a626_at_googlegroups.com>


On Wednesday, January 21, 2015 at 6:00:04 PM UTC+1, Lew Pitcher wrote:
> On Wednesday January 21 2015 11:44, in comp.databases.mysql, "Kiuhnm Mnhuik"
> <gandalf23_at_mail.com> wrote:
>
> > I don't understand why this works as expected:
> > select *
> > from games
> > order by 2
> > but this doesn't:
> > select *
> > from games
> > order by 1--1
> > The "order by" is completely ignored.
>
> No, it isn't.
>
> In the first example
> > select *
> > from games
> > order by 2
> all rows are placed in order of "2". That is to say, each row is treated
> (for the purposes of ordering) as if the ordering key were the value
> of "2". Since /all/ rows have the same ordering key, there is nothing
> special about the resulting ordering; the rows come out in an order that is
> effectively random (possibly, the same order that they would come out with
> without the "order by" clause).

Not true. order by 2 means order by the second column. You can try it here: http://sqlzoo.net/wiki/SELECT_.._WHERE

>
> In the second example
> > select *
> > from games
> > order by 1--1
> (which is treated as
> > select *
> > from games
> > order by 1
> because a sequence of two dashes ("--") signifies the start of a comment),

Also not true. See here:
http://dev.mysql.com/doc/refman/5.1/en/comments.html

Try
  select 1--1
and you'll see. Received on Wed Jan 21 2015 - 18:11:07 CET

Original text of this message