I have a small mysql table (MySQL version 5.6.23) :
+-----------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------------+------+-----+---------+----------------+
| id | int(6) unsigned | NO | PRI | NULL | auto_increment |
| dividends | float(8,6) | YES | | NULL | |
+-----------+-----------------+------+-----+---------+----------------+
My where clause follows the row-subqueries syntax.
If I do:
SELECT id, dividends FROM test
where (id,dividends) >= (660,0.5);
or
SELECT id, dividends FROM test
where (id,dividends) >= (660,CAST(0.5 AS DECIMAL(8,6)));
I get this result:
+-----+-----------+
| id | dividends |
+-----+-----------+
| 660 | 0.500000 |
| 661 | 0.470000 |
| 662 | 0.470000 |
| 663 | 0.470000 |
| 664 | 2.580000 |
| 665 | 2.581000 |
...
It seems to me that dividends >= 0.5 is not taken into consideration. Why?
You're using row constructors. MySQL treats them exactly like rows of a table. Thus WHERE (id,dividends) >= (660,0.5)
effectively does the same as:
ORDER BY id,dividends
;
Find the point at which (660,0.5)
would sit within that ordering;
Filter for only those records that are equal to or greater than that point in the ordering.
Consequently, it is the same as WHERE (id=660 AND dividends>=0.5) OR id>660
.
It appears as though the logic you really wish to express is WHERE id>=660 AND dividends>=0.5
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With