簡體   English   中英

使用codeigniter從兩個表中獲取記錄,其中所有匹配的記錄都來自第一個表

[英]Get Record from two table using codeigniter where all matching record from first table

我有兩個表:

  1. 學生[id,studname,學校,出價...]
  2. 出勤率[id,sid,bid,attenDate,...]

sid:學生編號
出價:批次ID

我正在嘗試從某個特定日期的同一批次的attendanceattendanceStudent表中獲取記錄。

但我得到的記錄/列表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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM