为了账号安全,请及时绑定邮箱和手机立即绑定

不是唯一的表/别名(codeigniter)

不是唯一的表/别名(codeigniter)

PHP
一只斗牛犬 2021-10-08 13:10:07
错误编号: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%'


查看完整回答
反对 回复 2021-10-08
  • 1 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号