where for inner join

3

As I have three WHERE tables

select login, nome_hotel from extranet_login, extranet_hoteis, hoteis 
where extranet_login.id_login=extranet_hoteis.id_login 
and extranet_hoteis.id_hotel=hoteis.id_hotel 
and extranet_login.login='admin';

for INNER JOIN

SELECT login, nome_hotel
FROM extranet_login
INNER JOIN extranet_hoteis ON extranet_login.id_login = extranet_hoteis.id_login
INNER JOIN hoteis ON hoteis.id_hotel = extranet_hoteis.id_hotel
INNER JOIN extranet_login ON extranet_login.login = 'admin';

Is it wrong?

    
asked by anonymous 09.06.2016 / 11:06

1 answer

2

The SQL syntax would look something like this:

select login, nome_hotel
  from extranet_login ext_log
 inner join extranet_hoteis ext_hot on ext_hot.id_login = ext_log.id_login
 inner join hoteis hot on hot.id_hotel = ext_hot.id_hotel
 where ext_log.login = 'admin';

However, for this type of query where there is a WHERE clause, it may be interesting to create temporary tables, in order to reduce the query universe. For this case it looks ok, since there is filtering by a specific user.

    
09.06.2016 / 11:16