我希望单个查询能够多次选择,我的目的是减少mysql进程,所以我使用这个查询,但它不起作用:
SELECT *
FROM `my_setting`
WHERE `setting` = `site_url`
AND `setting` = `site_name`
我使用select UNION
查询,但我认为它不会减少内存。
答案 0 :(得分:3)
试试这个:
SELECT * FORM `my_setting` WHERE (`setting` = `site_url` OR `setting` = `site_name`)
应该让你到达你需要去的地方。
答案 1 :(得分:3)
我想你想要
:SELECT * FROM my_setting
WHERE `setting` in ('site_url', 'site_name') -- if site_url is a literal string
或
SELECT * FROM my_setting
WHERE `setting` in (site_url, site_name) -- if site_url is a column name