Select to List data from another table

Asked

Viewed 115 times

1

I have a system that registers personal data enc_dados_pessoais and another table that stores complementary data enc_dados_complementares.

In the table personal data the user registers only the basic information and by clicking on move forward, goes to complementary data. I need to list only users who have not completed the complementary data.

To primary key table enc_dados_pessoais is IdUsuarios and the foreign key table enc_dados_complementares is IdUsuarios. So I did it this way:

SELECT * FROM enc_dados_principais princ LEFT JOIN enc_dados_complementares
comp ON princ.IdUsuarios <> comp.IdUsuarios;

But it is not returning who did not fill out, only who filled out the complementary data.

I’ve tried to use INNER JOIN, RIGHT JOIN and JOIN, but it didn’t work either.

  • 2

    you can use not exists or not in. Have a look here. http://answall.com/questions/62925/not-in-ou-not-exists-qual-use

  • Thanks Marconi. I used not in and it worked perfectly.

  • Not at all @Jose.Marcos

1 answer

3


Based on comment by Mr Marconi, solved the problem using the NOT IN:

select * from enc_dados_principais where IdUsuarios not in 
(SELECT IdUsuarios FROM enc_dados_complementares);
  • When possible, mark the answer as accepted by clicking on the mark below the score. =)

  • Hello qmechanik, I tried to do this but it says "You can accept your own answer in 2 days" ... but I marked the comment of Marconi as useful.

Browser other questions tagged

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