select - 来自两个 tables 的简单 select 记录

我有 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'

相似文章

javascript - Sorting 在另一个排序中

我有一组具有多个属性的数据,我希望它们排序的主要方式是在项目A之后放置项目B,但我不想影响这些项目之外的顺序。数据集(不分先后):记录1记录2记录3(具有项目A属性)记录4记录5(项目A)数据集(按A...

随机推荐

最新文章