我正在开发系统并创建发票。我想要没有发票的记录。
我正在尝试编写一个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
并得到以下结果:
哪个给出所有值,哪个记录也不用NULL值创建(我想让那个[e_id-> 2 from result])。我只想提取该空值记录的主ID。
答案 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;