"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 this in CodeIgniter? Is there any function for this? I explored the network so much, but could not find: /

appreciates! thanks,

+6
sql return codeigniter
source share
4 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(); 
+7
source share

Using

 $this->db->limit(1); 
+3
source share

Not sure about the encoder, but you can make regular choices and ordering and just use the first record to be returned, i.e. ignore those that come after that.

Basically, this is what the SQL engine does for you when you specify TOP 1 .

0
source share
 SELECT * FROM table LIMIT 1 

is the syntax for mySQL

-one
source share

All Articles