简体   繁体   中英

re-create a statement using inner join

I have a statement as the following :

select nomF from fournisseur as f, usine as u, puf, produit as p
where f.numF = puf.numF
and u.numU = puf.numU
and p.numP = puf.numP
where u.villeU in ('Paris','Créteil')

I want to re-create it using Inner Join , but I don't know how, because of the multiple joints in it.

This is what I tried, but I don't know if it's correct:

select nomF from fournisseur 
inner join puf on numF
inner join usine on numU
inner join produit on numP
where usine.villeU in ('Paris','Créteil')

Could someone please tell me if the statement I wrote using inner join will return the same result as the first one.

if not, what's the mistake I've made.

Thanks in advance.

With an inner join you still need to specify the columns to join on like you did with your where clause

select nomF 
from fournisseur f
inner join puf ON f.numF = puf.numF
inner join usine u ON u.numU = puf.numU
    AND u.villeU in ('Paris','Créteil')
inner join produit p ON p.numP = puf.numP

Many databases support the using syntax. This allows you to do what you seem to want to do:

select nomF
from fournisseur inner join
     puf
     using (numF) inner join
     usine 
     using (numU) inner join
     produit 
     using (numP)
where usine.villeU in ('Paris','Créteil');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM