【发布时间】:2021-12-30 07:40:33
【问题描述】:
我有两张桌子:
TableOne
| id | name | orgId |
|---|---|---|
| id-1 | One | org-1 |
| id-2 | Two | org-1 |
| id-3 | Three | org-1 |
| id-4 | Four | org-2 |
TableTwo
| id | status |
|---|---|
| id-1 | Ok |
| diff-id-1 | Ok |
| diff-id-2 | Ok |
如何编写查询以从orgId=org-1 和userId 在TableTwo 中不存在 的TableOne 检索记录?
在 JS 中我会写一个 if 作为两个 for 循环。
我写了一个声明的开头:
SELECT * from schema.TableOne
WHERE orgId = 'org-1'
但我不知道如何检查TableOne id 到TableTwo id。
结果应该是:
| id | name | orgId |
|---|---|---|
| id-2 | Two | org-1 |
| id-3 | Three | org-1 |
【问题讨论】:
标签: sql database postgresql