想要在每个条件下放置MySql限制

时间:2015-09-21 05:41:37

标签: mysql

我想通过限制每个参数来优化我的MySql条件。

当前查询

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

我得到两个条件的结果都有50行。现在我想在每个类似条件的基础上得到结果,例如

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


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

我想将上述两个查询结合起来,其中第一个查询获得50条记录,下一条查询获得50条记录。

3 个答案:

答案 0 :(得分:0)

您可以尝试使用UNION ALL

$date_from = $entity->getDatefrom();
$date_to = $entity->getDateto();
$workdays = 0;
for ( $i = clone $date_from; $i <= $date_to; $i->setTimestamp(strtotime($i->format('Y-m-d') . " +1 day") )  )
{
    if ( !in_array($i, $freedays))
    {
        if ( date('N', strtotime($i->format('Y-m-d') ) ) < 6 )
        {
            $workdays++ ;
        } 
    }
}

答案 1 :(得分:0)

尝试联盟

ImageView img = (ImageView) poplayout.findViewById(R.id.popupimg);
String serverpath = "yourimage path on server";
URL imageURL;

try {
    imageURL = new URL(serverpath +""+ aux);
    Bitmap imageBitmap = BitmapFactory.decodeStream(imageURL.openStream());
    img.setImageBitmap(imageBitmap);
} catch (Exception e) {
    e.printStackTrace();
}

答案 2 :(得分:0)

您应该使用Union Operator,然后:

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

UNION ALL

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