Why does using the AND operator work with JOIN, even without a WHERE clause?

Good afternoon, I just noticed. If I write a mysql query with a JOIN in it, for example:

Select Car, Vendor from Cars JOIN Vendor On Vendor.IdCar=Car.IdCar WHERE  Car="Brand"

He will return that car, which is equal to the "Brand".

But I noticed that if I structure the request this way:

Select Car, Vendor from Cars JOIN Vendor On Vendor.IdCar=Car.IdCar AND Car="Brand" 

It will return the same as the previous request. Noticed that I used AND instead of WHERE. I also tested the PHP queries I worked with. For example:

Select Car, Vendor from Cars JOIN Vendor On Vendor.IdCar=Car.IdCar AND Car=$brand

instead

Select Car, Vendor from Cars JOIN Vendor On Vendor.IdCar=Car.IdCar WHERE Car=$brand

So, the question I ask is this: why does the second query work? This is because JOIN was used because I was sure the WHERE clause was necessary before AND?

+4
source share
4 answers

WHERE ON (). , AND, OR NOT (, , ( ))

  • WHERE - ()
  • table-expression JOIN table-expression ON condition - , .
+2

JOIN ; , , , AND.

, , , join, , ; , .

, . join where. , , , .

+4

join inner join, on. , where. outer join ( ), null , , where - , .

+1
source

This is for readability, so you can put a sentence onin a sentence whereand everything will be done correctly:

Select Car, Vendor from Cars JOIN Vendor where Vendor.IdCar=Car.IdCar AND Car="Brand";

And this is also true:

Select Car, Vendor from Cars, Vendor where Vendor.IdCar=Car.IdCar AND Car="Brand";

But it cannot perform outer join (left join or right join)

0
source

Source: https://habr.com/ru/post/1651171/


All Articles