选择语句奇怪的行为

时间:2011-06-30 06:56:59

标签: mysql sql

我有以下表格:

+---------------+----------+------+-----+---------+----------------+
| Field         | Type     | Null | Key | Default | Extra          |
+---------------+----------+------+-----+---------+----------------+
| id            | int(11)  | NO   | PRI | NULL    | auto_increment |
| CAMXTimeStamp | datetime | YES  |     | NULL    |                |
| CAMXMessage   | longtext | YES  |     | NULL    |                |
+---------------+----------+------+-----+---------+----------------+

我正在尝试选择ID最低的记录:

select id from camxmessages having min(id);

然后桌子丢失了所有记录,我没有得到任何结果,知道我做错了什么?

2 个答案:

答案 0 :(得分:4)

SELECT *
FROM camxmessages 
ORDER BY id
LIMIT 1

答案 1 :(得分:4)

SELECT MIN(ID)
FROM CAMXMESSAGES