Re: SQL query

by "David Clapper" <dclapper(at)clioassociates.com>

 Date:  Wed, 4 Oct 2000 18:43:54 -0400
 To:  "Sue Bailey" <sue(at)bartandsue.co.uk>,
<hwg-techniques(at)hwg.org>
 References:  barnum
  todo: View Thread, Original
Hi Sue,

(1) If I understand the SQL spec correctly, "officially" you're not
guaranteed to get the records back in any order.  If you want to guarantee a
specific order, you need to use ORDER BY.  (This is not to say that a
specific implementation (e.g., MySQL) will not return the records in, say,
the order they were added to the database.  I just wouldn't count on it.)

(2) About the only way I can think of (off the top of my head) to get the
results to come out the way you want is to do individual SELECT statements,
including a time stamp in the SELECT list, UNION the SELECTs togethether,
and ORDER BY the timestamp.  Some SQL expert may come up with something
really slick

HTH ... .

David Clapper
Vice-President & Chief Architect
Clio Associates
70 Pavilion St.
Rochester, NY 14620  USA
Voice: +1.716.442.5407
Fax: +1.716.442.5993
Cell: +1.716.259.3699
e-mail: dclapper(at)clioassociates.com
PGP public key ID: 0xC67E9E98


----- Original Message -----
From: Sue Bailey <sue(at)bartandsue.co.uk>
To: <hwg-techniques(at)hwg.org>
Sent: Wednesday, October 04, 2000 10:40 AM
Subject: SQL query


> Hi all!
>
> If I have a SQL query such as SELECT * FROM table WHERE item = '3' OR item
=
> '2' OR item = '1' , and don't have any ORDER BY clause, the result I get
> from MySQL seems to automatically order itself by item (i.e. it would give
> me the results to the above ordered 1 - 2 - 3).
>
> Firstly, is this correct - I'm sure yesterday it was ordering according to
> the values for item I was giving it! -- which is what I want it to do.
>
> Secondly, is there any way get it to respect the order I've given it,
seeing
> as the array of items is totally arbitrary and bears no relation (nor
could
> be made to bear any relation) to any sorting of the db.
>
> (The item values are cookies from a shopping cart, so the only way I can
see
> to keep it matching the other relevent cookies -- quantities etc -- would
be
> to make multiple queries, one for each item. Seems a bit heavy handed to
> me!)
>
> Any thoughts would be very welcome to my weary brain!! And I apologise if
I
> haven't made sense ;-)
>
> Sue
>
>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA