Home > database >  Left the table with the problem of query results
Left the table with the problem of query results

Time:09-18

 SELECT * FROM tb_cm_integral_type a 
LEFT the JOIN tb_cm_integral_type b
ON a. ` pare_typ_id `=b. ` typ_id ` WHERE a. ` typ_id `='I00'


And
 SELECT * FROM tb_cm_integral_type a 
LEFT the JOIN tb_cm_integral_type b
ON a. ` typ_id `=b. ` pare_typ_id ` WHERE a. ` typ_id `='I00'

The result is not the same as

Change the WHERE clause to the AND different
 SELECT * FROM tb_cm_integral_type a 
LEFT the JOIN tb_cm_integral_type b
ON a. ` pare_typ_id `=b. ` typ_id ` AND a. ` typ_id `='I00'


A great god, o analysis

CodePudding user response:

This question is very simple, the first two statements of table a and table b, although have pare_typ_id and typ_id fields, but the content of the storage is different, so the results of a query is different also,
The third statement, to say the LEFT JOIN, this statement ON the content, can ensure the main table data integrity, but after the WHERE, is a strong correlation, WHERE conditions do not conform to, after the main table data will be defect,

CodePudding user response:

CodePudding user response:

In the LEFT JOIN cases, literally to switch statements, meaning is different.
  • Related