[PLUG] Re: SQL Syntax

Randal L. Schwartz merlyn at stonehenge.com
Mon Nov 6 16:47:16 UTC 2006


>>>>> "Mark" == Mark A Turner <turner at glsuite.com> writes:

Mark> ORDER BY is based on the table your selecting from, not the data your
Mark> selecting.

I'm with Russell on this.  ORDER BY is looking at the result set,
not the original table.  If you don't select something, you can't
ORDER BY it.

As an indication of that, I often use "ORDER BY 2" to order by the second
column of the result rows.

At least in standard SQL.  We're not talking about the seriously dainbramaged
MySQL here.  (Hint: please stop using MySQL... PostgreSQL is far more standard
and useful and scaleable.)

At least PostgreSQL tells you that you can't order by something that you
haven't selected or computed.  MySQL breaks again by letting you ask for
something that you aren't getting, but not telling you about it.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!




More information about the PLUG mailing list