Error running INTERSECT on Mysql

Asked

Viewed 62 times

0

inserir a descrição da imagem aqui

I want to select employees from the employee table who are managers, for this I’m trying to use the INTERSECT but it’s not working, I think the picture says it all too, there would be another way to do it?

  • Ever tried to put the space in * from?

  • I just put and the same thing

  • And correct the table name for "Managers"?

  • I just tried that tbm kkkk

1 answer

1


For example you presented the code below will serve:

Select Gerentes.*, Funcionario.* from Funcionario JOIN Gerentes ON (Funcionario.Nome = Gerentes.Nome)

Only a caveat. In the image that showed there is no key between the two tables (Managers and Employee). I did JOIN with the field NAME, Yeah, it was the only field I saw I could capture, but that’s not ideal.

If possible create a foreign key in the table so that this JOIN is more effective and useful ( in case there are two employees or managers with the same name this instruction will not work)

Creating a foreign key in Mysql

How to add a Foreign key to an already created table

Adding a foreign key to mysql

What is the use of foreign keys?

  • thanks a lot for the tip, but how do I create a foreign key? using his code?

  • Not at all, friend! Actually, Voce can create by the Mysql prompt or by some manager that Voce uses (Mysql Workbench for example). I changed my answer and added some links that clarify several points about foreign key.

  • makes a difference if the key is a string or int? in case using the employee and manager code

  • It does not, but good practice recommends that it be a whole.

Browser other questions tagged

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