我有两张桌子。
表A:
class YourController extends Controller{
$helpers = array('Paginator');
public fn(){
$view = new View(null);
var_dump($view->paginator->params());
}
}
表B:
root_id, root_text
现在word_id , word_text,root_text
的某些记录具有root_texts,Table B
中可能不存在。
因此我尝试使用左连接。
Table A
我只会获得与 select *
from A a , B b
where a.root_text=+b.root_text
匹配的记录。
如果我使用新方式
root_text
我得到了很多额外的记录。我正在使用MySQL 5.6.1.7
更新:
http://sqlfiddle.com/#!9/7b32a/2
查询我正在运行
Select
*
from
A left join B on a.root_text= b.root_text
我做错了什么?
结果你会看到很多不需要的记录。过滤器verse_no,word_no无效。
更新
问题出在左联接之后我们必须使用
select * from word_detail w left join roots r
on r.root_text =w.root
and w.surah_no=1
and w.verse_no=1
and w.word_no=1
答案 0 :(得分:1)
如果您希望TableB中的所有记录都不在表A中,您应该使用它:
Select *
from
B left join A
on a.root_text= b.root_text
where
a.root_text is null
或者如果你想要相反 - 来自tableA的所有记录都不在tableB上:
Select *
from
A left join B
on a.root_text= b.root_text
where
b.root_text is null
不过,这不是MySQL上的左连接:
select * from A a , B b where a.root_text=+b.root_text
但会产生一个简单的INNER JOIN
答案 1 :(得分:1)
+=
运算符不是标准SQL,而是特定于Oracle RDBMS,因此它在MySQL上无法正常工作。
LEFT JOIN
语法是正确的,“许多额外记录”源于表格中的数据。您可能希望使用某种WHERE
作为过滤器或聚合来对结果集进行分组,以使其更易于管理。
答案 2 :(得分:0)
您的第一个示例是内部联接,它解释了为什么您没有获得与您离开时一样多的结果。左连接也可以被认为是左外连接。