Where for Inner Join

Asked

Viewed 122 times

3

as I have three tables WHERE

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';

You are wrong?

  • 1

    I don’t understand why they gave you -1. I found the question pertinent. + 1 for you to help restore a little reputation. Unfortunately there are many people who keep giving -1 without following the correct rules of the site.

  • I tried to help, check the answer sff

1 answer

2

The SQL syntax would be 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 universe of query. For this case it seems ok, since there is filtering by a specific user.

  • Gave errors :/ Query failed: ERROR: Missing FROM-clause entry for table "ext_hot" LINE 4: ... INNER JOIN hotels hot ON hot.id_hotel = ext_hot.id...

Browser other questions tagged

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