…如果只有一个匹配的可能条目(主键的WHERE子句)?
SELECT `x`
FROM `unicorns`
WHERE `id` = 123
LIMIT 1
…相同,但现在它是DELETE:
DELETE FROM `unicorns`
WHERE `id` = 123
LIMIT 1
……和更新:
UPDATE `unicorns`
SET `rainbows` = `rainbows` + 1
WHERE `id` = 123
LIMIT 1
附:列ID是主键,因此它是唯一的.
谢谢你的建议!
最佳答案
这取决于您是否有列索引
原文链接:https://www.f2er.com/mysql/433034.htmlDELETE FROM `unicorns` WHERE `id` = 123 LIMIT 1
如果id是主键,则没有意义,但是
DELETE FROM `unicorns` WHERE `noindexoclumn` = 123 LIMIT 1
会给你提高性能