Select with 2 Inner Join returns no result

Asked

Viewed 31 times

1

I have a relational database that has 3 tables: tb_functionaries, tb_licencas and tb_tipo_licencas, each with their respective primary keys. The tb_licencas table, however, has the keys of the other two tables. The question is: how to make a query in the tb_licencas table that brings the fields of this table and the fields of the other two associated each to its own key? I tried using Inner Join, but it only works with two tables. When I try to add a 2 Inner Join the query simply does not return me anything. Follow the Query:

SELECT tb_licencas.IdLicença, tb_licencas.IdFuncionário, tb_funcionarios.Nome, tb_funcionarios.Matrícula, tb_funcionarios.Admissão, tb_funcionarios.Regime, tb_funcionarios.Cargo, tb_tipos_licencas.IdTipo, tb_tipos_licencas.Descrição, tb_licencas.Órgão, tb_licencas.Início, tb_licencas.Duração, tb_licencas.TérminoIndeterminado, tb_licencas.Cancelado, tb_licencas.Cancelamento, tb_licencas.CancelamentoMotivo, tb_licencas.CancelamentoObservação, tb_licencas.Anotações, tb_licencas.Inativo
FROM tb_licencas 
INNER JOIN tb_funcionarios ON tb_licencas.IdFuncionário = tb_funcionarios.IdFuncionário 
INNER JOIN tb_tipos_licencas ON tb_licencas.IdTipo = tb_tipos_licencas.IdTipo

If anyone can give me a light, I’d really appreciate it.

The database I’m using is SQL CE.

  • 1

    Syntactically correct. The problem of not returning anything may have to do with the data in the tables. If possible mount an example in Sqlfiddle so we can test.

  • True... I had released the data manually on the tables and the data was inconsistent. The problem is only the primary and foreign key values of the tb_employees table that were.

  • By the way, if there is a problem of inconsistency, it is advisable that in the drawing of the tables, the Foreign Keys are there, just to avoid launching data in tb_licencas that are not in the mother tables.

No answers

Browser other questions tagged

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