说我有一条SQL语句:
SELECT *
FROM MY_TABLE
WHERE MY_FIELD IN ('AAA','BBB','CCC', 'DDD');
我的桌子是:
ID FIELD1
1 AAA
2 CCC
3 DDD
4 FFF
上面的sql语句会给我数据库中的3条记录。
我的问题是如何更改我的SQL语句以找到它找不到的记录? (即告诉我BBB没有匹配)
答案 0 :(得分:1)
您需要LEFT JOIN
,NOT IN
或NOT EXISTS
:
SELECT v.*
FROM (SELECT 'AAA' as f FROM DUAL UNION ALL
SELECT 'BBB' as f FROM DUAL UNION ALL
SELECT 'CCC' as f FROM DUAL UNION ALL
SELECT 'DDD' as f FROM DUAL
) v LEFT JOIN
MY_TABLE t
ON v.f = t.my_field
WHERE t.my_field IS NULL;
答案 1 :(得分:0)
$calculator = new calculator();
echo $calculator->addition(10)->multiplication(2)->getResult(); // 20