在mysql中加入的反向作用

时间:2018-08-10 11:56:20

标签: mysql database

我正在开发系统并创建发票。我想要没有发票的记录。

我正在尝试编写一个MySQL查询,在这里我需要不能与另一个表连接的记录。换句话说,在另一个表中没有链接记录的记录。

我尝试了以下查询

SELECT exports.id as e_id,export_invoices.id as i_id 
FROM exports 
LEFT JOIN export_invoices ON export_invoices.export_id = exports.id

并得到以下结果:

enter image description here

哪个给出所有值,哪个记录也不用NULL值创建(我想让那个[e_id-> 2 from result])。我只想提取该空值记录的主ID。

1 个答案:

答案 0 :(得分:1)

只需在查询中添加where条件-

SELECT exports.id as e_id,export_invoices.id as i_id 
FROM exports LEFT JOIN export_invoices on export_invoices.export_id = exports.id
WHERE export_invoices.id IS NULL;