如何在codeigniter中处理sub_query?

时间:2019-01-10 21:15:25

标签: php database codeigniter-3

我正在使用codeingniter 3,我想从我的自定义查询中获取结果。您可以看到此查询:

SELECT
    *
FROM
    (
        SELECT
            *
        FROM
            `Role`
        LIMIT 10,5) AS T
    ORDER BY
        id DESC

之前,我使用了以下方法:

$this->db->select('*');
$this->db->from('Role');
$this->db->limit(5, 10);
$first_result = $this->db->get_compiled_select();
$this->db->select('*');
$this->db->from("( $first_result ) AS T");
$this->db->order_by('id DESC');
$this->db->get();

我得到这个错误:

Error Number: 1327
Undeclared variable: 5 )
SELECT * FROM ( SELECT * FROM `Role` LIMIT 10, `5 )` AS `T` ORDER BY `id` DESC

是否可以通过Codeigniter运行此查询?

0 个答案:

没有答案