为了简化这个数据库查询(每个请求必须运行很多次),是否需要进行一些更改,比如使用in子句或其他什么?

SELECT `id`
FROM `tablename`
WHERE `columnname1` = "longer-value" OR
      `columnname2` = "longer-value" OR
      `columnname3` = "longer-value" OR
      `columnname4` = "longer-value" OR
      `columnname5` = "longer-value" OR
      `columnname6` = "longer-value" OR
      `columnname7` = "longer-value" OR
      `columnname8` = "longer-value" OR
      `columnname9` = "longer-value" OR
      `columnname10` = "longer-value"

请注意,此查询检查10个不同列上的该值。

最佳答案

我以前真的做过…

WHERE "longer-value" IN (`rowname1`, `rowname2`, ... , `rownameN`)

08-18 10:47