2015-11-28 70 views
0

我想要選擇所有價格顯示,然後我想更新所有價格。我可以在MySQL中編寫子查詢,但是如何在zend框架查詢樣式中執行此操作?Zend框架子查詢更新和選擇

MySQL查詢是

SELECT price FROM mag1.catalog_product_option_type_price where option_type_id in 
(SELECT option_type_id FROM mag1.catalog_product_option_type_value where option_id in 
(SELECT option_id FROM mag1.catalog_product_option where product_id= 11)); 

回答

0

寫準確查詢:

$select1 = new Select(); 
$select1->from('catalog_product_option') 
->columns('option_id') 
->where(array('product_id' => 11)); 

$where2 = new Where(); 
$select2 = new Select(); 
$select2->from('catalog_product_option_type_value') 
->columns('option_type_id') 
->where($where2->in('option_id', $select1); 

$where = new Where(); 
$select = new Select(); 
$select->from('catalog_product_option_type_price') 
->columns('price') 
->where($where->in('option_type_id', $select2); 

但爲什麼不嘗試

$select = new Select(); 
$select->from(array('p' => 'catalog_product_option_type_price')) 
->join(array('v' => 'catalog_product_option_type_value'), 'p.option_type_id = v.option_type_id', array()) 
->join(array('o' => 'catalog_product_option'), 'v.option_id = o.option_id', array()) 
->columns('price') 
->where(array('o.product_id' => 11)); 

這應該給予同樣的結果。