Code: Select all
mysql> desc attributes;
+---------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| parent | int(11) | YES | MUL | 1 | |
| type | int(11) | YES | MUL | 1 | |
| name | varchar(128) | YES | | NULL | |
| created | timestamp | NO | MUL | CURRENT_TIMESTAMP | |
| changed | timestamp | NO | MUL | 0000-00-00 00:00:00 | |
+---------+--------------+------+-----+---------------------+----------------+
Code: Select all
mysql> select * from attributes order by changed desc,id;
+------+--------+------+-----------------------------+---------------------+---------------------+
| id | parent | type | name | created | changed |
+------+--------+------+-----------------------------+---------------------+---------------------+
| 1 | 1 | 1 | root | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
| 2 | 1 | 1 | Item property name | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
...
Code: Select all
mysql> select * from attributes where changed <= "2018-01-17 13:42:03" and id >100 order by changed desc, id asc limit 5;
+-----+--------+------+-----------------+---------------------+---------------------+
| id | parent | type | name | created | changed |
+-----+--------+------+-----------------+---------------------+---------------------+
| 101 | 1 | 2 | Client type | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
| 102 | 1 | 2 | Document source | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
| 500 | 1 | 4 | application | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
| 501 | 1 | 4 | audio | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
| 502 | 1 | 4 | chemical | 2018-01-17 13:42:03 | 2018-01-17 13:42:03 |
+-----+--------+------+-----------------+---------------------+---------------------+
5 rows in set (0.00 sec)