SELECT to fill in a field

Asked

Viewed 136 times

1

Good afternoon, I have a table called Pessoa and another Matricula, I need to make a query that returns the fields to me name, license plate and person of them, where name and person are on the table Pessoa and enroll in the table Matricula to return in select that each informed letter will fetch in the BD by passing the informed letters.


Example 1

He will make the query as he enters the letters.

exemplo 1

This select is as follows, working for what you need in another field.

SELECT seq_pessoa AS id
                 , UPPER(nome) AS text
              FROM pessoa
             WHERE nome ILIKE '%". $nome ."%'

Doubt

But now I have the following select that is not working properly

SELECT m.matricula AS id
                 , UPPER(p.nome) AS text
              FROM matricula as m
              JOIN pessoas as p USING (seq_pessoa)

What I need is instead to enter the user’s name, enter the registration code and it return me his name.

  • Like the table matricula and pessoas connect? What foreign key?

  • @Pedropaulo PK table Pessoa is the seq_pessoa, she who connects the Matricula

1 answer

2


SELECT m.matricula AS id
                 , UPPER(p.nome) AS text
              FROM matricula as m
              JOIN pessoas as p USING (seq_pessoa)
WHERE m.matricula = matricula

Remembering that the variable matricula must be informed, as was reported in the example code the variable $name.

  • Exactly what I needed, thank you very much.

Browser other questions tagged

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