首页 > 解决方案 > 如何在 where not exists 查询上应用子查询?

问题描述

我在下面有这段代码:

select * from outerb where not exists(select * from wms where 
outerb.barcode = wms.barcode);

我想在此处添加此代码:

select concat('0',barcode) from outerb

我这样做的原因是因为我需要0在所有条形码之前添加一个额外的并将它与另一个表连接在一起。

这是我到目前为止所尝试的:

select concat('0',barcode) as x from outerb join wms on outerb.x = 
wms.barcode;

但出现错误Column 'barcode' in field list is ambiguous

标签: mysqlsql

解决方案


在条形码列之前使用表别名

select concat('0',outerb.barcode) as x from
outerb join wms on concat('0',outerb.barcode) = wms.barcode
where not exists (select * from wms where concat('0',outerb.barcode) = wms.barcode)

推荐阅读