Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15190

Re: Problem creating a series of tables

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: Problem creating a series of tables
Date 2015-04-02 22:32 +0200
Organization PointedEars Software (PES)
Message-ID <1928459.l4EcNPIvok@PointedEars.de> (permalink)
References <arrknd1koidz.1uimiwnq5sefe.dlg@40tude.net> <mfet7b$qs$1@dont-email.me> <1957209.MyoqzTBkhW@PointedEars.de> <mfjj60$5nq$2@dont-email.me>

Show all headers | View raw


Jerry Stuckle wrote:

> On 4/2/2015 8:50 AM, the pedantic troll Thomas 'Pointed Head' Lahn wrote:
>> Denis McMahon wrote:
>>> Remember that if you don't specify a sort order in the mysql query, the
>>> ordering of the records it returns is random.
>> 
>> Incorrect.  The ordering is undefined if the table has no keys that
>> define
>> sort order.  For example, for a InnoDb table named `test` that has
>> 
>> | Field   Type    Null    Key     Default Extra
>> | id      int(10) unsigned        NO      PRI     NULL    auto_increment
>> 
>> the result of the MySQL query
>> 
>> | SELECT * FROM `test` LIMIT 1
>> 
>> will be the record with the smallest `id` field value.
>> 
>> $ php -v
>> PHP 5.6.7-1 (cli) (built: Mar 24 2015 12:30:15)
>> Copyright (c) 1997-2015 The PHP Group
>> Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
>>     with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend
>> Technologies
>>     with Xdebug v2.2.6, Copyright (c) 2002-2014, by Derick Rethans
>> 
>> $ mysql -V
>> mysql  Ver 14.14 Distrib 5.5.42, for debian-linux-gnu (x86_64) using
>> readline 6.3
> 
> Incorrect (again).  It will return the first row in the table - which
> may or may not be the one with the smallest 'id' value.

Si tacuisses, philosophus mansisses.

,----
| mysql> create temporary table tmp (id int(10) primary key not null);
| Query OK, 0 rows affected (0.01 sec)
| 
| mysql> explain tmp;
| +-------+---------+------+-----+---------+-------+
| | Field | Type    | Null | Key | Default | Extra |
| +-------+---------+------+-----+---------+-------+
| | id    | int(10) | NO   | PRI | NULL    |       |
| +-------+---------+------+-----+---------+-------+
| 1 row in set (0.01 sec)
| 
| mysql> insert into tmp values (1);
| Query OK, 1 row affected (0.00 sec)
| 
| mysql> insert into tmp values (0);
| Query OK, 1 row affected (0.01 sec)
| 
| mysql> select * from tmp;
| +----+
| | id |
| +----+
| |  0 |
| |  1 |
| +----+
| 2 rows in set (0.00 sec)
`----

> By definition, order is undefined in a SQL database unless the ORDER BY
> clause is specified.

So much for theory – for which you want to cite evidence.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Problem creating a series of tables richard <noreply@example.com> - 2015-03-31 12:14 -0400
  Re: Problem creating a series of tables Paul Herber <paul@pherber.com> - 2015-03-31 19:09 +0100
    Re: Problem creating a series of tables richard <noreply@example.com> - 2015-03-31 14:30 -0400
  Re: Problem creating a series of tables Denis McMahon <denismfmcmahon@gmail.com> - 2015-03-31 19:40 +0000
    Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-31 16:19 -0400
      Re: Problem creating a series of tables Richard Yates <richard@yatesguitar.com> - 2015-03-31 18:07 -0700
        Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-31 21:23 -0400
      Re: Problem creating a series of tables Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-04-01 12:19 +0200
        Re: Problem creating a series of tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-02 15:23 +0200
          Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-02 10:17 -0400
    Re: Problem creating a series of tables richard <noreply@example.com> - 2015-03-31 20:14 -0400
      Re: Problem creating a series of tables Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-01 02:44 +0000
        Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-31 23:06 -0400
          Re: Problem creating a series of tables richard <noreply@example.com> - 2015-04-01 00:09 -0400
            Re: Problem creating a series of tables Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-01 20:37 +0000
              Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-01 17:08 -0400
    Re: Problem creating a series of tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-02 14:50 +0200
      Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-02 10:20 -0400
        Re: Problem creating a series of tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-02 22:32 +0200
          Re: Problem creating a series of tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-03 00:44 +0200
            Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-02 19:22 -0400
            Re: Problem creating a series of tables Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-02 19:24 -0400
            Re: Problem creating a series of tables "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-03 01:46 +0200
              Re: Problem creating a series of tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-03 20:45 +0200
          Re: Problem creating a series of tables Richard Yates <richard@yatesguitar.com> - 2015-04-02 15:59 -0700
            Re: Problem creating a series of tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-03 01:10 +0200
              Re: Problem creating a series of tables Richard Yates <richard@yatesguitar.com> - 2015-04-02 18:44 -0700

csiph-web