我有 2 个 tables(table_A 有一列 products_id 和 table_B 有 products_id 和 state)我的查询需要 select,table_A 中的所有 products_id 都与 table_B 连接,除了这些 products_id 的 state = open。我试过了,但它只显示 table_B 记录中的记录
SELECT * FROM table_A WHERE EXISTS (SELECT product_id, state FROM table_B WHERE table_A.product_id = e_productBAK1FEB.product_id AND state == 'open'
回答1
尝试
select table_A.* from table_A
join table_B on table_A.product_id = table_B.product_id
where table_B.state != 'open'