我想查询数据库,以便获得所有字段(其中field = x)、所有字段(其中field = y)以及仅一个字段(其中field = z)一个查询,这样我就可以获得如下内容:
(...) content = something, field = x
(...) content = something, field = x
(...) content = something, field = x
(...) content = something, field = x
(...) content = something, field = y
(...) content = something, field = y
(...) content = something, field = z (only one field where field = Z)
我尝试使用不同的但它不起作用。对这个有什么想法吗?非常感谢!
最佳答案
(select * from your_table where field in ('x', 'y'))
union all
(select * from your_table where field = 'z' limit 1)
关于mysql - 仅选择一个等于 "z"的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24935078/