Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码给了我以下错误:
组功能使用无效
$query = mysql_query("SELECT `text` FROM `text` WHERE `id`=max(id)"); if(!$query) die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['text']; }
我的错误在哪里?
如果您想要具有最高 id 的行,您可以使用: SELECT text FROM text ORDER BY id DESC LIMIT 1
SELECT text FROM text ORDER BY id DESC LIMIT 1
WHERE子句影响单个行,而HAVING子句影响聚合(GROUP BY子句的结果)。行条件必须限制在WHERE子句中,聚合函数(如 MAX)必须在HAVING子句中使用。
WHERE
HAVING
GROUP BY
你可以这样做:
SELECT * FROM text WHERE id = (SELECT MAX(id) FROM text);