INNER JOIN does not return bank result

1

I'm trying to use this code:

SELECT *
FROM tb_trabalhador
INNER JOIN tb_detalhe_trabalhador ON Tb_trabalhador.id = tb_detalhe_trabalhador.tb_trabalhador_id

And it returns the result in white.

Is there a way to get around this with another code?

tb_detail_worker:

  'id' int(11) NOT NULL AUTO_INCREMENT,
  'tb_trabalhador_id' int(11) DEFAULT NULL,
  'tb_funcoes_id' int(11) DEFAULT NULL,
  'MedicaValidade' date DEFAULT NULL,
  'MedicaAnexo' longblob,
   (...)

tb_worker:

'id' int(11) NOT NULL AUTO_INCREMENT,
'Nome' varchar(200) DEFAULT NULL,
'Morada' text,
'Tipo' varchar(45) DEFAULT NULL,
(...)
    
asked by anonymous 24.02.2014 / 10:32

2 answers

4

The syntax of your Join is apparently correct.

What remains for you to check is if you enter the details of the worker if the value of tb_trabalhador.id is being included in tb_detalhe_trabalhador.tb_trabalhador_id , so that the relation is complete, since the condition is just this: / p>

tb_trabalhador.id = tb_detalhe_trabalhador.tb_trabalhador_id

To get the correct ID, if you are entering a new worker and its details in the same series of operations, one possibility is to use the LAST_INSERT_ID( ) (en) shortly after entering the worker, and then entering the details with the returned ID by the function.

Leveraging, see this question , and note the IDs of the example tables and the results if the condition of ON is satisfied or not.

    
24.02.2014 / 12:31
2

Update

Following conversation in the comments of this answer, it was clear that your query is not returning results because when you insert the records in the database you are not applying to the field tb_trabalhador_id of your table tb_detalhe_trabalhador value which has been registered in the id field of your tb_trabalhador table.

With the exception of the typing error in the table name that I mentioned in the "original response", your query is well constructed and does not return results unless there are actually results related to the fields indicated therein.

Original Response

Your query is in good shape and format, but I think you have a typo in the table name:

Tb_trabalhador

It should be with t lowercase:

tb_trabalhador

Or vice versa.

Inquiry:

SELECT *
FROM tb_trabalhador
INNER JOIN tb_detalhe_trabalhador ON tb_trabalhador.id = tb_detalhe_trabalhador.tb_trabalhador_id

9.2.2 Identifier Case Sensitivity

  

In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses the default file system type (HFS +) that is not case sensitive. However, Mac OS X also supports UFS volumes, which are case sensitive just on any Unix.

What translated:

  

In MySQL, the databases correspond to the directories within the data directory. Each table within a database corresponds to at least one file in the database directory (and possibly more, depending on the storage mechanism). Consequently, sensitivity to uppercase or lowercase letters by the underlying operating system plays a role in the sensitivity of uppercase or lowercase letters in database names and tables. This means that database names and tables are not case-sensitive in Windows, but they are in most Unix varieties. One notable exception is Mac OS X, which is Unix-based but uses a standard, case-insensitive file system type (HFS +). However, Mac OS X also supports UFS volumes, which are sensitive, just like on any Unix.

    
24.02.2014 / 11:01