2017-07-16 3 views
-1

Ich habe dieses Modell zuvor verwendet und es funktioniert, und jetzt weiß ich nicht, warum $ this-> db-> distinct(); funktioniert nicht.So verwenden Sie distinct im Codeigniter

if($this->input->post('Status')) 
    {               
     $this->db->where('Status', $this->input->post('Status')); 
    } 
    if($this->input->post('PlateNo')) 
    {               
     $this->db->like('PlateNo', $this->input->post('PlateNo')); 
    } 
    if($this->input->post('user.userId')) 
    {               
     $this->db->like('user.userId', $this->input->post('user.userId')); 
    } 

    $this->db->select('*'); 
    $this->db->distinct(); 
    $this->db->from($this->table); 

    $this->db->join('user', 'user.userId = loanapplication.userId', 'left'); 
    $this->db->join('loanrequest', 'loanrequest.ApplicationNo = loanapplication.ApplicationNo', 'left'); 
    $this->db->join('loanapproval', 'loanapproval.RequestNo = loanrequest.RequestNo', 'left'); 
    $this->db->join('collateraldetails', 'collateraldetails.ApplicationNo = loanapplication.ApplicationNo', 'left'); 
    $this->db->join('paymentdetails', 'paymentdetails.ApplicationNo = loanapplication.ApplicationNo', 'left'); 
    $this->db->join('loanpayment', 'loanpayment.PaymentId = paymentdetails.PaymentId', 'left'); 
    $this->db->join('vehicleinformation', 'vehicleinformation.vehicleNo = collateraldetails.vehicleNo', 'left'); 

enter image description here

Antwort

2

Try this:

$this->db->group_by('name_of_the_column_you_dont_want_repeated'); 
+0

Dank für Ihre Antwort. –

+0

Wann verwenden Sie group_by oder distinct? Was ist der Unterschied? –

+1

Mit 'GROUP BY' können Sie Aggregatfunktionen wie' AVG', 'MAX',' MIN', 'SUM' und' COUNT' verwenden. Andere Hand 'DISTINCT' entfernt nur Duplikate. Weitere Informationen finden Sie unter https://stackoverflow.com/questions/164319/is-there-any-difference-between-group-by-and-distinct –

Verwandte Themen