从Codeigniter活动记录中的子查询中选择 [英] SELECT from subquery in Codeigniter Active Record

查看:75
本文介绍了从Codeigniter活动记录中的子查询中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Codeigniter ActiveRecord中执行以下查询:-

How would I do the following query in Codeigniter ActiveRecord : -

SELECT *, 

(SELECT 
        image_path
    FROM
        image
    WHERE
        image_table = 'model'
            AND image_table_id = model_id
    GROUP BY image_table_id
    LIMIT 1) AS ModelImg 

FROM

   (SELECT 
      *
   FROM
      vw_newcars
    where offer_table = 'derivative'
    order by offer_order
   ) x

WHERE make_name = 'Fiat'
group by offer_table_id
limit 12

我遇到的问题是如何从Active Record中的子查询中进行选择.

The part I'm having problems with is how to do a select from subquery in Active Record.

我没有看到 from_select 函数或文档中没有类似的东西.

I don't see a from_select function or anything comparable in the documentation.

推荐答案

我设法通过将 from 子查询放入初始选择语句中来使查询工作:

I managed to get the query to work by putting the from sub_query into the initial select statement :

$this->db->select("*, 
  (select image_path from image where image_table = 'model' and image_table_id = model_id
  group by image_table_id limit 1) as ModelImg FROM 
  (SELECT * FROM $view where offer_table = 'derivative' order by offer_order) x"); 

这篇关于从Codeigniter活动记录中的子查询中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆