How do I bring the same numbers from other tables?

Asked

Viewed 51 times

0

Good morning, I’d like that help.

I have a table of "INSCRIPTION" where it has 2 foreign keys (CAND_SQ and CANDPL_SQ). Both foreign keys have a CPF field.

I would like to know how I bring the numbers that are equal within the inscription.

That is, I currently have a REGISTRATION where it can be done in two different ways. Regular Registration and Late Registration. When I Register Late, if I have already done the Regular Registration I cannot do the Late Registration.

  • 1

    Do you use Mysql or Microsoft SQL Server? You mean that the contents of the CAND_SQ and CANDPL_SQ fields are only CPF’s and you want to know which ones repeat in the REGISTRATION table?

  • It is because I can give the select in both Mysql and SQL Server, here. Exact, I want to know which ones repeat in the table INSCRIPTION.

  • Search for the clause HAVING that should meet your needs. As I do not understand how is organized your table I can not kick an SQL command.

1 answer

1

To see which Cpfs repeat themselves:

Select t.cpf
from tabelaComCampoCAND_SQ t
inner join tabelaComCampoCANDPL_SQ t2 on t1.cpf = t2.cpf

But if the need is just a validation before registration delay, just vc consult in the regular registration table if the CPF already exists:

Select 1
from tabelaComCampoCAND_SQ t
WHERE t.cpf = (valorCpf)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.