请参阅下面的 DDL:
CREATE TABLE TestTable(id int, [name] varchar(30))
CREATE TABLE TestTable2(id int, [name] varchar(30))
INSERT INTO TestTable (id,[name]) values (1,'')
INSERT INTO TestTable (id,[name]) values (2,'Martin')
INSERT INTO TestTable2 (id,[name]) values (1,null)
INSERT INTO TestTable2 (id,[name]) values (2,'Martin')
select TestTable.* from TestTable
LEFT JOIN TestTable2
ON TestTable.id=TestTable2.id
and TestTable.[name]= TestTable2.[Name] and NOT (TestTable.[name] ='' and TestTable2.[name] is null)
where testtable2.id is null
SELECT 返回一行,我希望它不会返回任何内容。我希望它返回 none 的原因与下面的 SQL 语句返回 none 的原因相同:
select TestTable.* from TestTable
LEFT JOIN TestTable2
ON TestTable.id=TestTable2.id
and TestTable.[name]= TestTable2.[Name]
where testtable2.id is null and NOT (TestTable.[name] ='' and TestTable2.[name] is null)
为什么第一条 SQL 语句返回一行?ON 子句应使用以下条件过滤掉那些记录:NOT (TestTable.[name] ='' and TestTable2.[name] is null)。返回的一行包含此条件。为什么?