[英]sql select table where a column not in a set with exception another column equal to something
[英]Inside a select, just select a row from another table where one column is equal to something
我有一個 select 查詢工作正常,但一個信息在另一個表中,但另一個表是瘋狂的。
在此表中,僅當列等於 CPF 時才需要的信息
但我不能像往常一樣做這個查詢
我的查詢
select
name,
date,
CPF
from user
是的,兩個表之間有一個主鍵,codintfunc
但是,如果有 2 個條件,我如何從另一個表中獲取 select CPF,並且在 select 查詢中我無法執行此操作。
PS:抱歉我的英語不好,我是巴西人
我已經在 select 中嘗試了 select,加入和在哪里,但不幸運
更多信息
因為數據庫有敏感信息,e 由於來自巴西的 LGPD,我制作了一些視覺表來幫助理解我需要什么。
我正在使用 3 個表來獲取我在此查詢中需要的所有數據
我需要的結果是
您可以加入cod
並添加其他條件以僅過濾您需要的typedoc
:
SELECT t1.cod, t1.name, t2.typedoc, t2.numdoc, t3.mat_escocial
FROM table_1 t1
JOIN table_2 t2 ON t1.cod = t2.cod AND t2.typedoc = 'cpf'
JOIN table_3 t2 ON t1.cod = t3.cod
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.