This depends on the bank engine. Semantically speaking, the JOIN
is clearer, but from the performance point of view you need to see the query execution plan.
I set up this table from your example and extract the execution plan from both queries and the result was the same:
Schema (Mysql v5.7)
create table Bancos (
Cod int primary key,
Nome varchar(50)
);
create table OperacoesBanco (
Cod int primary key,
CodBanco int references Bancos(Cod),
ValorOp float,
Historico varchar(100)
);
Query #1
explain SELECT
b.Nome,
o.ValorOp,
o.Historico
FROM
Bancos b,
OperacoesBanco o
WHERE
b.Cod = o.CodBanco;
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
| --- | ----------- | ----- | ---------- | ------ | ------------- | ------- | ------- | --------------- | ---- | -------- | ----------- |
| 1 | SIMPLE | o | | ALL | | | | | 5 | 100 | Using where |
| 1 | SIMPLE | b | | eq_ref | PRIMARY | PRIMARY | 4 | test.o.CodBanco | 1 | 100 | |
Query #2
explain SELECT
*
FROM
Bancos
INNER JOIN
OperacoesBanco
WHERE
Bancos.Cod = OperacoesBanco.CodBanco;
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
| --- | ----------- | -------------- | ---------- | ------ | ------------- | ------- | ------- | ---------------------------- | ---- | -------- | ----------- |
| 1 | SIMPLE | OperacoesBanco | | ALL | | | | | 5 | 100 | Using where |
| 1 | SIMPLE | Bancos | | eq_ref | PRIMARY | PRIMARY | 4 | test.OperacoesBanco.CodBanco | 1 | 100 | |
So for this table model, the result is the same from the point of view of plan and performance. Of course, when adding other criteria this can change according to how the engine of the bank, but simply analyzing the link of the tables, for the mysql
, the performance will be the same.
Ran and exported from DB Fiddle: https://www.db-fiddle.com/
I do not believe that there is any difference in performance, even because the optimisers will take care of this aspect. I prefer the option by spelling out INNER JOIN to make it easier for humans to read (explicit vs implicit). Anyway you can eliminate your doubt by evaluating the query plan generated by ANALYZE for both.
– anonimo