Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"SELECT TOP 1" equality for codeigniter?

I need to get only 1 record from sql result. we use "SELECT TOP 1" in standard sql, but how can we do that in CodeIgniter? Is there any func for that? I researched so much on net, but could not find :/

appreciate! thanks,

like image 385
designer-trying-coding Avatar asked Oct 27 '09 11:10

designer-trying-coding


2 Answers

with LIMIT

$this->db->limit(1);
$query = $this->db->get('my_table');
$myRow = $query->row();

with OFFSET and LIMIT

$query = $this->db->get('mytable', 0, 1);
$myRow = $query->row();
like image 67
David Elizondo Avatar answered Oct 29 '22 10:10

David Elizondo


Use

$this->db->limit(1);
like image 44
Zahymaka Avatar answered Oct 29 '22 10:10

Zahymaka