Use subqueries or joins? Alternatives to left | right join? [duplicate]

0

Good morning. My Doubt is: Which is better in terms of readability and performance, use subqueries whenever possible or use the "join" format? What is more important, readability or performance? I would understand that many would say that if the difference in performance is not going to be very large that the readability prevails.

Select * from t1
inner join t2 on t1.k1=t2.k2

O

Select * from t1,t2
where t1.k1=t2.k2

Is there an alternative way to use left or right join to get the null values, as in oracle when using the (+)?

select n1,n2
from t1 left join t2 on t1.n1=t2.n2

 n1 n2
 -- --  
 2  2
 3  3
 1  NULL
 4  NULL

A year or so ago I remember a complete guide to mysql or sql to dry with all the syntax of each aspect of mysql, detailed and explained how each keyword and operation worked and now I am not able to find such documentation. Only a very summary documentation of the sentence syntax.

    
asked by Lorthas 15.07.2017 в 00:17
source

1 answer

2

Left / right Join is visualized in this way:

it and can be described as all the elements of A and B that are contained in A (Leaving the elements of B that are not in A out)

In set logic we can see it as

  

A ∩ (A ∩ B).       To intersection of A intersection B

Can be represented with the Query:

SELECT *
  FROM A                 //Seleccionamos el conjunto A
  JOIN B ON B.id = A.id  // + Union A + B En este caso comparten id
 WHERE.....              //el where esta de mas aqui
    
answered by 15.07.2017 в 00:54