0

With the below query metioned in here

SELECT * FROM Table1 t1 
LEFT JOIN Table2 t2 ON t1.id = t2.id 
WHERE t1.user='bob';

Mosty Mostacho stated that WHERE is execute before the JOIN.

But if other sources like this, it said "Normally, filtering is processed in the WHERE clause once the two tables have already been joined".

So I am confused which one is right? Can I check the order with EXPLAIN? If yes, how? I can't understand which field in the Explain output state the order.

JJJ
  • 32,902
  • 20
  • 89
  • 102
HKIT
  • 628
  • 1
  • 8
  • 19
  • Why does it matter? – Strawberry Jan 14 '19 at 07:51
  • 4
    A SQL query is not procedural in nature.A simple join have hundreds of different execution plans and it is optimiser decides which will be best way to produce answer. – Kandy Jan 14 '19 at 07:53
  • BTW, there is an mistake in this query. Should be **LEFT JOIN Table2 t2**, not **LEFT JOIN Table2 t1** – Ivan Olshansky Jan 14 '19 at 08:08
  • thanks for pointing out the mistake, i will edit it – HKIT Jan 14 '19 at 08:33
  • Read about relational query implementation/optimization in some introduction to SQL or relational DBs. Not a couple random answers on the web. The language defines a result, the DBMS can do anything to calculate it. Are you asking about what the result is defined to be? If you are asking about the implementation behaviour, that depends on the implementation. See the relevant chapter of some DB textbook(s) (dozens are free online in pdf) or even https://en.wikipedia.org/wiki/Query_optimization. – philipxy Jan 14 '19 at 08:56

0 Answers0