Using LIMIT 1 in MySQL

后端 未结 5 2041
猫巷女王i
猫巷女王i 2021-02-01 02:54

When is it appropriate to add LIMIT 1 at the end of the query in MySQL. I normally add it in DELETE but I\'ve seen it being used with INSERT a and even UPDATE. Is it an overkill

5条回答
  •  春和景丽
    2021-02-01 03:23

    Extremely rarely useful. Either you know your database enough to be certain > that your WHERE matches a UNIQUE condition, or you don't, in which case you > should spend a little more time looking at your database and learning SQL

    There are instances where a limit 1 is REALLY useful. For example, a table without a unique key. If we have five of the exact same, then limit one will work.

提交回复
热议问题