简体   繁体   English

不工作在sql INNER JOIN中?

[英]Not work WHERE IN sql INNER JOIN?

I want WHERE data select with $find, but it(WHERE) not work in following query and my output is There is not , how fix it? 我希望WHERE数据选择$ find,但它(WHERE)在以下查询中不起作用,我的输出There is not ,怎么修复它?

$find="hello";
$query = $this->db->query('
SELECT tour_foreign.name, 
       tour_foreign_residence.name_re, 
       tour_foreign_airline.name_airline, 
       tour_foreign.service, 
       tour_foreign.date_go, 
       tour_foreign.date_back, 
       tour_foreign.term 
FROM   tour_foreign 
       INNER JOIN tour_foreign_residence 
         ON ( tour_foreign.id = tour_foreign_residence.relation ) 
       INNER JOIN tour_foreign_airline 
         ON ( tour_foreign.id = tour_foreign_airline.relation ) 
WHERE  tour_foreign.name LIKE "%' . $find . '%" 
        OR tour_foreign_residence.name_re LIKE "%' . $find . '%"


');

if ($query->num_rows() > 0) {
    foreach ($query->result() as $val) {
        echo $val->name . '<br>';
    }
} else {
    echo 'There is not';
}

You have an extra comma before the WHERE (after tour_foreign_airline.relation). WHERE之前有一个额外的逗号(在tour_foreign_airline.relation之后)。

Edit: I see you fixed it now, but the JOIN still looks wrong. 编辑:我看到你现在修好了,但是JOIN看起来仍然不对劲。 Try this: 尝试这个:

INNER JOIN tour_foreign_residence
ON (tour_foreign.id = tour_foreign_residence.relation)
INNER JOIN tour_foreign_airline
ON (tour_foreign.id = tour_foreign_airline.relation)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM