I want a single query to multiple select, my purpose is to reduce mysql process, so I use this query, but it does not work:
SELECT *
FROM `my_setting`
WHERE `setting` = `site_url`
AND `setting`开发者_运维问答 = `site_name`
I use select UNION
query, but I think it doesn't reduce memory.
I think you want either:
SELECT * FROM my_setting
WHERE `setting` in ('site_url', 'site_name') -- if site_url is a literal string
or
SELECT * FROM my_setting
WHERE `setting` in (site_url, site_name) -- if site_url is a column name
Try this:
SELECT * FORM `my_setting` WHERE (`setting` = `site_url` OR `setting` = `site_name`)
Should get you where you need to go.
精彩评论