【发布时间】:2013-02-27 04:46:01
【问题描述】:
我有 2 个选择语句。
1- select sm.id, IFNULL(sm.unit_price,0) as unit_price
from crm_stock_manager sm
left join crm_purchase_order_items poi on poi.id = sm.purchase_order_item_id and poi.is_del = 0
left join crm_products p on poi.product_id = p.id and p.is_del = 0
where sm.is_del = 0 and IFNULL(sm.unit_price, '') != '' and p.id = 253 order by sm.created_on;
2- select 0 as id ,price as unit_price from crm_products where id = 253 and is_del=0;
如果第一个选择语句返回一个空结果,那么我想运行第二个选择语句。
请帮帮我。
【问题讨论】:
-
只需执行 2 个单独的查询,一个接一个
-
有没有办法在 mysql 上做到这一点?
-
有什么理由在 mysql 中这样做吗?
-
这是否意味着如果 srm_stock_manager.unit_price 为 NULL,您需要选择 crm_products.price?
-
没有。如果 crm_stock_manager 表包含我需要从该表中获取记录的任何数据。否则它将从 crm_products 表中获取。
标签: mysql