FOOD TABLES (SQL SERVER) [closed]

2

Oops, good morning.

I have a sql database, in this database there is a table for People, it is a second table for registering credentials, in a third table and made the association of the credential with the person, ie there is a Table called CRED_PESSOAS, where through person's code is the number of the credential is made the association of the credential to person.

I have a client who requested to feed this credential information through scripts, I already fed the two tables (PEOPLE AND CREDENTIALS) my question is how to create a condition, where I take for example the credential X for person Y, credential and for person x and so on.

Thank you in advance. Gustavo Braga

    
asked by anonymous 24.08.2016 / 17:15

1 answer

1

You need a restrictive relationship between tables, as shown below:

    SELECT pessoa.*, credencial.*
      FROM pessoa
INNER JOIN pessoa_credencial ON pessoa_credencial.id_pessoa = pessoa.id
INNER JOIN credencial ON credencial.id = pessoa_credencial.id_credencial

Remembering that the relationship in this way, if your database has more than one credential for the same person or more than one person for a credential) may return more than one line.

    
24.08.2016 / 17:56