I have two table "A" and "B". I want to select record from table "A" only if "B" table not that requested values according to given ID. In my code I pass my "ID" to select record. I want to select record from "A" table if only "B" table doesn't exist requested record.
我有两张桌子“A”和“B”。我想要从表A中选择record,只当B表中没有根据给定ID请求的值。在我的代码中,我将我的ID传递给select record。我想要从“A”表中选择record,如果只有“B”表不存在则请求记录。
1 个解决方案
#1
2
You can pretty much put that into SQL words
你可以把它放到SQL语句中。
SELECT *
FROM TABLE A
WHERE A.ID = ?
AND A.ID NOT IN (
SELECT B.ID
FROM TABLE B
WHERE B.ID = ?
)
Use the ?
as placeholder with a PreparedStatement
(safe) or replace them manually with the value you want (unsafe).
使用?使用PreparedStatement (safe)作为占位符,或者使用您想要的值(不安全)手动替换它们。
#1
2
You can pretty much put that into SQL words
你可以把它放到SQL语句中。
SELECT *
FROM TABLE A
WHERE A.ID = ?
AND A.ID NOT IN (
SELECT B.ID
FROM TABLE B
WHERE B.ID = ?
)
Use the ?
as placeholder with a PreparedStatement
(safe) or replace them manually with the value you want (unsafe).
使用?使用PreparedStatement (safe)作为占位符,或者使用您想要的值(不安全)手动替换它们。