0

特定のアイテムの最大入札額を選択し、最大入札額が見つかった行から詳細情報を返そうとしています。

現時点で私が持っている

    $item_id = $this->input->post('item_id');
    $this->db->from('bids');
    $this->db->where('item_id', $item_id);
    $this->db->where('outbid_alert', '1');
    $this->db->select_max('bid_amount');
    $query = $this->db->get();
    return $query->result();    

これはアイテムの最大入札額を返します。それは私が得た限りです。その行から残りのフィールドを取得する最良の方法は何ですか? 別のクエリを実行するか、サブクエリを使用しますか?

ありがとう!

4

1 に答える 1

1

が最も高い行からフィールドを返したい場合は、最初の行bid_amountだけを選択します。ORDER BY bid_amount

$item_id = $this->input->post('item_id');

$this->db->from('bids');
$this->db->where('item_id', $item_id);
$this->db->where('outbid_alert', '1');

$this->db->select('*');

$this->db->order_by('bid_amount', 'DESC');
$this->db->limit(1);

$query = $this->db->get();
return $query->result();
于 2013-02-05T15:10:53.257 に答える