All pastes #827814 Raw Edit

Miscellany

public text v1 · immutable
#827814 ·published 2007-12-22 01:05 UTC
rendered paste body
mysql> SELECT * FROM accounts_transactions WHERE account_id = 622 AND status = 0;
+----+------------+---------+--------+------------+
| id | account_id | amount  | status | date       |
+----+------------+---------+--------+------------+
|  7 |        622 |   50.00 |      0 | 2007-12-14 |
|  8 |        622 |   50.00 |      0 | 2007-12-14 |
|  9 |        622 |   50.00 |      0 | 2007-12-14 |
| 10 |        622 |   50.00 |      0 | 2007-12-14 |
| 11 |        622 |   50.00 |      0 | 2007-12-14 |
| 12 |        622 |   50.00 |      0 | 2007-12-14 |
| 13 |        622 |   50.00 |      0 | 2007-12-14 |
| 15 |        622 |   50.00 |      0 | 2007-12-14 |
| 16 |        622 | 1049.99 |      0 | 2007-12-14 |
+----+------------+---------+--------+------------+
9 rows in set (0.00 sec)

so in this example:

since account 622, has status of 0, I want that very last row....

now in this next example:
mysql> SELECT * FROM accounts_transactions WHERE account_id = 622 AND status = 0;
+----+------------+---------+--------+------------+
| id | account_id | amount  | status | date       |
+----+------------+---------+--------+------------+
|  7 |        622 |   50.00 |      0 | 2007-12-14 |
|  8 |        622 |   50.00 |      0 | 2007-12-14 |
|  9 |        622 |   50.00 |      0 | 2007-12-14 |
| 10 |        622 |   50.00 |      0 | 2007-12-14 |
| 11 |        622 |   50.00 |      0 | 2007-12-14 |
| 12 |        622 |   50.00 |      0 | 2007-12-14 |
| 13 |        622 |   50.00 |      0 | 2007-12-14 |
| 15 |        622 |   50.00 |      0 | 2007-12-14 |
| 16 |        622 | 1049.99 |      1 | 2007-12-14 |
+----+------------+---------+--------+------------+
9 rows in set (0.00 sec)

since the last status is 1, this account would not be returned in the result set.