錯誤編號:1066不是唯一的表/別名:'posts'SELECT * FROM (SELECT id, title, keywords, 'posts' AS type FROM posts, postsUNION SELECT id, title, keywords, 'android' AS type FROM android, androidUNION SELECT id, title, keywords, 'mac' AS type FROM mac, 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();
1 回答

慕的地8271018
TA貢獻1796條經驗 獲得超4個贊
刪除表的所有第二個名稱并使用 UNION ALL 代替:
SELECT * FROM (
SELECT id, title, keywords, 'posts' AS type FROM posts
UNION ALL
SELECT id, title, keywords, 'android' AS type FROM android
UNION ALL
SELECT id, title, keywords, 'mac' AS type FROM mac
)t WHERE t.title like '%yj%' OR t.keywords LIKE '%yj%'
- 1 回答
- 0 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消