Trong sql i am using union tôi không biết cách viết nó trong zend db.Cách sử dụng union trong zend db
select m.*, 0 as is_shared from test m where user_id = $userId
union
select m.*,1 as is_shared from test m
join test_shares ms
where m.test_id = ms.test_id
and ms.email_address = $email
and m.url is not null;
Xin hãy giúp tôi ra ....
tôi đã cố gắng như thế này nhưng không sử dụng
$cols1 = array('test.*,0 as is_shared');
$select1 = $db->select()
->from ('test', $cols1)
->where ('user_id = ?', $userId);
$cols2 = array('test_shares.*', '1 as is_shared');
$select2 = $db->select()
->from ('test', $cols2)
->join ('test_shares', array())
->where ('test.test_id = test_shares.test_id')
->where ('test_shares.email_address = ?', $email)
->where ('test.url is NOT NULL');
$select = $db->select()
->union(array($select1, $select2))
->order('title');
Nó đang 'thử'. '0' AS 'is_shared' như thế này nhưng tôi cần như thế này 0 như is_shared. Nó đang dùng 'thử nghiệm'. '1' AS 'is_shared' như thế này nhưng tôi cần như thế này 1 như is_shared.