本文介绍了想要对每个 where 条件设置 MySql 限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过对每个参数设置限制来优化我的 MySql 条件.

I want to refine my MySql condition by putting limit on each parameter.

当前查询

Select * from product 
where name like "%abc%" or name like "%xyz%" 
limit 50

我得到了两种情况都有 50 行的结果.现在我想根据每个类似条件获得结果,例如

I got result having 50 rows for both condition. Now I want to get result on the base of each like condition such as

Select * from product 
where name like "%abc%" 
limit 50


Select * from product 
where name like "%xyz%" 
limit 50

我想将上述两个查询合并为一个,其中第一个查询有 50 条记录,下一个查询有 50 条记录.

I want to wrap up both above queries in one where I got 50 records for first query and another 50 for next one.

推荐答案

你应该使用 Union Operator,然后:

Select * from product 
where name like "%abc%" 
limit 50

UNION ALL

Select * from product 
where name like "%xyz%" 
limit 50

这篇关于想要对每个 where 条件设置 MySql 限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:00