Select only if the ID is in 2 tables

Asked

Viewed 54 times

0

I have 2 tables in Mysql, INSCRICAO1 and INSCRICAO2. Both have a field called COD that receives a user code.

To INSCRICAO1 stores your personal information To INSCRICAO2 saves user’s car information

I need to select the INSCRICAO1 only of users who own cars, ie that are also present in the table INSCRICAO2.

How to do, I tried with LEFT JOIN, but gave error.

  • 1

    You actually described the behavior of INNER JOIN. But with select itself, we can only help if you share your attempt. The way to do it depends on the data model, there is not enough information to give an accurate answer, I am marking as unclear.

  • The answer was this, INNER JOIN, thanks! Anyway I’ll improve the question.

2 answers

2

Do so:

SELECT * FROM  inscricao1 INNER JOIN inscricao2 ON inscricao1.cod = inscricao2.cod

0

I thought of a different way:

   SELECT a.cod, b.cod FROM inscricao1 as a, inscricao2 as b WHERE a.cod = b.cod;

So simple using alias.

Browser other questions tagged

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