开发者

How to multiple select in same table, in single query

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜