I have a select query working fine, but one information is in another table, but this another table is crazy.
In this table, the info a need is only where the column is equal to CPF
But I can't do this query like usually
My query
select
name,
date,
CPF
from user
Yes, there is a primary key between the two tables, codintfunc
But how I select CPF from the other table if theres 2 condition and inside the select query I can't do this.
PS: sorry my bad english, I'm Brazilian
I've tried select inside a select, joins and where, but no lucky
More Info
Because the database has sensitive information, e due to LGPD from Brazil, I made some visual sheet to help understand what I need.
I'm using 3 tables to acquire all data I need in this query
What I need from result is
CodePudding user response:
You can join on cod
and add additional conditions to filter only the typedoc
you need:
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