Different ways to do a query that performs an SQL merge

Asked

Viewed 59 times

3

I learned to do SQL queries with joins as follows:

SELECT u.NOME, e.RUA 
FROM usuarios u, endereco e 
WHERE e.ID_USUARIO = u.ID 
ORDER BY u.NOME 

As you can see, the query searches the name of users and the street of their address (using nicknames to simplify table names). About how this query was structured, the doubts are as follows:

  • This is a simplified way of making joins by not explicitly using JOIN, LEFT ON and type instructions?

  • How would the same query be using the join instructions explicitly?

1 answer

0


This is a simplified way of making joins by not explicitly using JOIN, LEFT ON and type instructions?

I would not say a "simplified" way, I would say an "alternative" way to do INNER Join, because doing left / right / full Outer would be more laborious.

I personally prefer to do the join using the keyword as it separates the Join conditions from the query conditions. Basically: let the join do the job of join and leaves the "where" do work of "where"

How would the same query be using the join instructions explicitly?

SELECT u.NOME, e.RUA
FROM usuarios u
INNER JOIN endereco e ON e.ID_USUARIO = u.ID
ORDER BY u.NOME 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.