簡體   English   中英

codeigniter 中的 INNER JOIN ON 條件

[英]INNER JOIN ON condition in codeigniter

這是我的 mysql 查詢

SELECT MAX(A.BID),B.* 
  FROM tbl_bid A 
 INNER 
  JOIN wl_customers B 
    ON A.customers_id=B.customers_id
 WHERE portfolio_id='$Id'

如何在 codeigniter 中編寫此查詢。

你也可以試試。 這也可以是其中一種方式

     $this->db->select('MAX(A.BID),wl_customers.*');
     $this->db->from('tbl_bid');
     $this->db->join('wl_customers ','tbl_bid.customers_id=wl_customers.customers_id');
     $this->db->where('portfolio_id',$Id,false)
     $result = $this->db->get();

就像是

$this->db->select('MAX(A.BID),B.*')
->join('wl_customers as B','A.customers_id=B.customers_id')
->where('portfolio_id',$Id)
->get('tbl_bid as A')
->row();

試試這個查詢。 它可能對你有幫助:

$this->db->select("B.*","MAX(A.BID)")
            ->from("tbl_bid A")
            ->join("wl_customers B","A.customers_id=B.customers_id")
            ->where("portfolio_id",$Id)->get()->result();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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