Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.php Subject: Re: Problem creating a series of tables Date: Thu, 02 Apr 2015 22:32:33 +0200 Organization: PointedEars Software (PES) Lines: 75 Message-ID: <1928459.l4EcNPIvok@PointedEars.de> References: <1957209.MyoqzTBkhW@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1428006874 31642 eJwNwokRwDAIA7CVymMD45BQ9h+hPQlG4Q0n6NjfRMpbqAz07OpeGrVNpjsy4zjyaD9T8Ir8ABodEMQ= (2 Apr 2015 20:34:34 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 2 Apr 2015 20:34:34 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwCAIA7CXlNIq5yCD/09YQmirjotyDqf6XQd4dwYQEZiVz9X91bp0R6Ns0lssM57c2faJVmKwf0mvFTo= Cancel-Lock: sha1:UzMMcaD/VYvr3LvF7UMXHWIT0Vk= X-NNTP-Posting-Host: eJwNy8kBwCAIBMCWWC6TckSW/kvQ/0xYIs/yjPSYGGi1HPlJbRTVoNbo7crELM4TjDrSr823LydlEdA= Xref: csiph.com comp.lang.php:15190 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.