[英]Get Record from two table using codeigniter where all matching record from first table
我有兩個表:
sid:學生編號
出價:批次ID
我正在嘗試從某個特定日期的同一批次的attendance
和attendance
的Student
表中獲取記錄。
但我得到的記錄/列表student
,其id
是無濟於事attendance
。
學生桌:
出勤表:
在這兩種情況下,我都只有兩條記錄。 我希望有3個學生名單。
SELECT * FROM students s LEFT OUTER JOIN attendance a ON s.id = a.sid WHERE s.bid=1 AND a.attenDate='2017-03-18'
$condition = ['s.bid'=>$bid,'a.attenDate'=>$adate];
$listattend = $this->db->select('*')
->from('students s')
->join('attendance a', 's.id = a.sid', 'right outer')
->where($condition)
->get();
return $listattend->result();
嘗試這個
SELECT a.*,s* FROM attendance a LEFT JOIN students s ON a.sid = s.id AND a.bid=s.bid WHERE DATE(a.date) = "2017-02-05"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.