簡體   English   中英

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

[英]Not unique table/alias (codeigniter)

錯誤號:1066

不是唯一的表格/別名:“帖子”

SELECT * FROM(SELECT idtitlekeywords ,'posts'AS類型FROM postsposts UNION SELECT idtitlekeywords ,'android'AS類型FROM androidandroid UNION SELECT idtitlekeywords ,'mac'AS類型從macmac )t到'%yj%'之類的t.title或像'%yj%'這樣的t.keywords

模型:

  $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();

刪除表的所有第二個名稱,並改用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%'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM