I have a problem when I run sub-query in from clause.
Here is my code
$subquery = "select column1, column2 from table limit 10, 10"
$this->db->select(column1, false)->from("( $subquery ) as b");
$this->db->get();
I get database error "Undeclared variable: 10" And print my query is:
select column1 from ((select column1, column2 from table limit 10, `10` ) as b)
How can I remove this character "`"
You can use $this->db->_protect_identifiers=false; which will remove all backticks on this query.
So your query will be something like:
$subquery = "select column1, column2 from table limit 10, 10"
$this->db->_protect_identifiers=false;
$this->db->select(column1, false)->from("( $subquery ) as b");
$this->db->_protect_identifiers=true; // You can make it true again here to avoid removing of backtickes in further code unnecessarily
$this->db->get();
try this:
$subquery = "select column1, column2 from table limit 10, 10";
$this->db->query("Select column1 from (".$subquery.") as b" );