【发布时间】:2020-01-10 07:23:01
【问题描述】:
如何使用 PHP CodeIgniter 框架进行 UNION 查询我在执行此查询时遇到错误
Every derived table must have its own alias
型号
function search_blog($title){
$query = $this->db->query("SELECT * FROM (
SELECT id,section,title,img,year,lastupdateon AS ondate,'moves' AS dept,STATUS FROM movies
UNION
SELECT ID,section,Title,img,year,lastupdateon AS ondate,'kid' AS dept,STATUS FROM kids
UNION
SELECT ID,views,Title,img,version AS year,ondate,'software' AS dept,STATUS FROM soft
UNION
SELECT ID,section,Title,img,'PC Game' AS year,ondate,'game' AS dept,STATUS FROM games
UNION
SELECT ID,season,Title,img,type AS year,lastupdatedon AS ondate,'tvshow' AS dept,STATUS FROM tvshows
)");
$this->db->like('Title', $title , 'after');
$this->db->order_by('ondate', 'DESC');
$this->db->limit(10);
return $this->db->get($query)->result();
}
如何修改
【问题讨论】:
标签: php sql codeigniter search union