【发布时间】:2019-07-13 15:50:03
【问题描述】:
错误号:1066
不是唯一的表/别名:'posts'
SELECT * FROM (SELECT
id,title,keywords, 'posts' AS type FROMposts,postsUNION SELECTid,title,keywords, 'android' AS 输入 FROMandroid,androidUNION SELECTid,title,keywords, 'mac' AS type FROMmac,mac)t WHERE t.title like '%yj%' OR t.keywords LIKE '%yj%'
型号:
$query = $this->input->GET('search', TRUE);
$this->db->select("id, title, keywords, 'posts' AS type");
$this->db->from("posts");
$query1 = $this->db->get_compiled_select('posts');
$this->db->select("id, title, keywords, 'android' AS type");
$this->db->from("android");
$query2 = $this->db->get_compiled_select('android');
$this->db->select("id, title, keywords, 'mac' AS type");
$this->db->from("mac");
$query3 = $this->db->get_compiled_select('mac');
$data = $this->db->query('SELECT * FROM (' . $query1 . ' UNION ' . $query2 . ' UNION ' . $query3 . ')' . "t WHERE t.title like '%$query%' OR t.keywords LIKE '%$query%'");
return $data->result();
【问题讨论】:
-
FROM posts, posts?你想做什么? -
喜欢来自 3 个表的帖子,android,mac
标签: php mysql sql codeigniter