0
I have the following query:
select
profissionais_ab.cns cns_medico,
profissionais_ab.cbo,
unidade_ab.nome
from
profissionais_ab
join unidade_ab on unidade_ab.id = profissionais_ab.unidade_id
Return me the following:
123456 | DENTISTA 1 | UNIDADE 1
789012 | DENTISTA 2 | UNIDADE 2
The table profissionais_ab
is composed of:
id integer
varchar
cbo varchar
cns varnish
integer unit
In the query I mentioned above, he pulls the data of a professional (the dentist), but in this same table there is the registration of the auxiliary
1 | DENTISTA 1 | DENTISTA | 123456 | 1
2 | DENTISTA 2 | DENTISTA | 789012 | 2
3 | DENTISTA 3 | DENTISTA | 345678 | 3
4 | AUXILIAR 1 | AUXILIAR | 901234 | 1
5 | AUXILIAR 2 | AUXILIAR | 567890 | 2
6 | AUXILIAR 3 | AUXILIAR | 234567 | 3
I need the result to come both the dentist and the auxiliary of the same unit:
123456 | DENTISTA 1 | UNIDADE 1 | AUXILIAR 1
789012 | DENTISTA 2 | UNIDADE 2 | AUXILIAR 2
Any suggestions?
Add a self-assembly of the professional table using the latter field as the joining criterion (my assumption is that such a field links a dentist to his auxiliary).
– anonimo
@anonimo can give a practical example? I can’t do
– Italo Rodrigo
My assumption is correct?
– anonimo
@anonimo Dentists and ASB are in the same table, what changes is the CBO field
– Italo Rodrigo
And how do I connect a dentist to his assistant?
– anonimo
@anonymous by the unit field, they must belong to the same unit
– Italo Rodrigo