开发者

How to multiple select in same table, in single query

开发者 https://www.devze.com 2023-03-22 17:24 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消