0

テーブルが 2 つあり、Zend で内部結合クエリを記述して、テーブル 1 から ID がテーブル 2 の ID と一致しないすべてのレコードを取得したい

$db = Zend_Db_Table::getDefaultAdapter();       
$select = $db->select()->setIntegrityCheck(FALSE); 
$select->from('cwi_company','*')->join('cwi_groupinglinks','cwi_company.id <> cwi_groupinglinks.orgId')->where('cwi_company.manage=1')->where('cwi_company.deleteOption=0');
$result =$select->fetchAll();       
return $result;
4

3 に答える 3

0

joinInner内部結合に使用

$select->from('cwi_company','*')->joinInner('cwi_groupinglinks','cwi_company.id != cwi_groupinglinks.orgId')->where('cwi_company.manage=1')->where('cwi_company.deleteOption=0');
于 2013-06-18T08:40:46.367 に答える
0

右側のテーブルに存在しないレコードを選択する必要がある場合は、左結合して値 == NULL を選択する必要があります。例:

$db = Zend_Db_Table::getDefaultAdapter();       

$select = $db->select()->setIntegrityCheck(FALSE); 
$select->from('cwi_company','*')
  ->joinLeft('cwi_groupinglinks','cwi_company.id = cwi_groupinglinks.orgId')
  ->where('cwi_company.manage=1')
  ->where('cwi_company.deleteOption=0');
  ->where('cwi_groupinglinks.orgId IS NULL')

$result = $select->fetchAll();
于 2013-06-18T08:44:25.350 に答える