2013-05-28 6 views
-1

этот запрос работает для деятельностикак объединить эти два запроса

$query1 = "select t.entity_id, t.parent_id, t.length,gu.measurement_unit_id 
    from tree t 
    left join units u 
    on t.parent_id = u.region_id 
    and u.activity_id IN (some activity_id) 
    left join product_grid_units gu 
    on u.id = gu.unit_id 
    WHERE t.entity_id IN (some region_id)"; 

и этот запрос работает для региона

 $query2 = "select t.entity_id, t.parent_id, t.length,gu.measurement_unit_id 
    from tree t 
    left join units u 
    on t.parent_id = u.activity_id 
    and u.region_id IN (some region_ids) 
    left join product_grid_units gu 
    on u.id = gu.unit_id 
    WHERE t.entity_id IN ("some activity_ids")"; 

, поэтому я хочу, чтобы объединить эти два querys ... может кто-нибудь помочь? ...

ответ

0

Использование UNION (неявный различны) или UNION ALL так:

select t.entity_id, t.parent_id, t.length,gu.measurement_unit_id 
from tree t 
left join units u on t.parent_id = u.region_id 
        and u.activity_id IN (some activity_id) 
left join product_grid_units gu on u.id = gu.unit_id 
WHERE t.entity_id IN (some region_id) 
UNION ALL 
select t.entity_id, t.parent_id, t.length,gu.measurement_unit_id 
from tree t 
left join units u on t.parent_id = u.activity_id 
        and u.region_id IN (some region_ids) 
left join product_grid_units gu on u.id = gu.unit_id 
WHERE t.entity_id IN ("some activity_ids") 
Смежные вопросы