How Limit Works In Select Query (Doc ID 2191019.1)

Last updated on OCTOBER 07, 2016

Applies to:

MySQL Cluster - Version 5.0 and later
Information in this document applies to any platform.

Goal

When it is executed one select query on one particular table it is getting two different responses:

mysql> SELECT col1 FROM table1 WHERE col2='admin' LIMIT 1;
+-----+
| col1  |
+-----+
| 176  |
+-----+
1 row in set (0.00 sec)

mysql> SELECT col1 FROM table1 WHERE col2='admin' LIMIT 1;
+----+
| col1 |
+----+
| 28   |
+----+
1 row in set (0.01 sec)

Sometimes it´s returning row id 176 and sometimes row id 28 . Also in this particular table there are total 47 entries exist matching this criteria.


mysql> SELECT COUNT(*) FROM table1 WHERE col2='admin' ;
+----------+
| count(*) |
+----------+
| 47           |
+----------+
1 row in set (0.00 sec)

 

 

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms