开发者

Clarification on PL/SQL JOINS in this Query

开发者 https://www.devze.com 2023-02-28 08:57 出处:网络
I have a Query returning 377 Rows Select Cm.Customerid,Cm.Customername,Ad.Addressid,Ad.Addressline1, Stm.Statename,Ctm.Cityname,Dm.Districtname

I have a Query returning 377 Rows

Select Cm.Customerid,Cm.Customername,Ad.Addressid,Ad.Addressline1,
Stm.Statename,Ctm.Cityname,Dm.Districtname 
 From Crm.Customers Cm 
inner join Crm.Customeraddress Ad on Ad.Customerid=Cm.Customerid
Inner Join Ehis.Statemaster Stm On Stm.Stateid=Ad.Stateid
Inner Join Ehis.Citymaster Ctm On Ctm.Cityid=Ad.Cityid
inner join Ehis.Districtmaster dm on Dm.Districtid=Ad.Districtid

But if i add one more join to this (i.e)

Select 
Cm.Customerid,Cm.Customername,Ad.Addressid,Ad.Addressline1,
Stm.Statename,Ctm.Cityname,Dm.Districtname 
 From Crm.Customers Cm 
inner join Crm.Customeraddress Ad on Ad.Customerid=Cm.Customerid
inner join crm.agreements ag on ag.customerid=cm.customerid
Inner Join Ehis.Statemaster Stm On Stm.Stateid=Ad.Stateid
Inner Join Ehis.Citymaster Ctm On Ctm.Cityid=Ad.Cityid
inner join Ehis.Districtmaster dm on Dm.Districtid=Ad.D开发者_如何学编程istrictid

My query is not returning any rows. Is there any Problem in using inner join for statemasters,city n district masters. Pls clarify the same.


The problem doesn't appear to be with statemaster, citymaster or districtmaster, as these are in your original query that returns data.

The additional line (below) looks to be the culprit.

inner join crm.agreements ag on ag.customerid=cm.customerid

Presumably there are no records on the agreements table with a matching customerid on the customers table.

To prove that is the case, you could change that line to

left join crm.agreements ag on ag.customerid=cm.customerid

If you get your 377 records back, then you'll need to check the data in agreements.

0

精彩评论

暂无评论...
验证码 换一张
取 消