S
S
Sasha Pleshakov2016-05-30 22:52:03
MySQL
Sasha Pleshakov, 2016-05-30 22:52:03

Which join is better (WHERE or JOIN)?

Scheme:
fac60f1505fe46bf999b22c12e4b88bd.PNG
Joining with JOIN:
5b729292d071406fa5840006a6b3746e.PNG
Code:

SELECT Мастеры.ФИО AS Мастер, Услуги.Название AS Название, 
Услуги.Стоимость AS Стоимость, Услуги.Половая_принадлежность AS [Половая принадлежность]
FROM Услуги 
INNER JOIN (Мастеры 
    INNER JOIN Мастер_Услуга 
    ON Мастеры.Код_Мастера=Мастер_Услуга.Код_Мастера) 
ON Услуги.Код_Услуги=Мастер_Услуга.Код_Услуги;

Joining with WHERE:
dfe7dcaef71941f0a27dd26f83c3e15b.PNG
Code:
SELECT Мастеры.ФИО AS Мастер, Услуги.Название AS Название, 
Услуги.Стоимость AS Стоимость, Услуги.Половая_принадлежность AS [Половая принадлежность]
FROM Мастеры, Услуги, Мастер_Услуга
WHERE Мастеры.Код_Мастера = Мастер_Услуга.Код_Мастера 
AND Услуги.Код_Услуги = Мастер_Услуга.Код_Услуги;

They output the same thing. What query is better to use for such purposes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2016-05-30
@mnepoh

So many different database tags, each database has its own profiling tools, run both queries through them. If both queries are equally fast, then the best option is the one that is more understandable and pleasant to you.

M
mletov, 2016-05-30
@mletov

The first option is not very good, because it contains a subquery, and this is an additional execution time.
The option with commas has a right to exist, but, in my opinion, it is not very convenient to read.
I would write like this

SELECT Мастеры.ФИО AS Мастер, Услуги.Название AS Название, Услуги.Стоимость AS Стоимость, Услуги.Половая_принадлежность AS [Половая принадлежность]
FROM Мастер_Услуга
INNER JOIN Мастеры
ON Мастеры.Код_Мастера = Мастер_Услуга.Код_Мастера 
INNER JOIN Услуги
ON Услуги.Код_Услуги = Мастер_Услуга.Код_Услуги

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question