开发者

Getting multiple values from a query

I write a query to get values from 3 tables but this is returning multiple values so can any one 开发者_JAVA技巧tell where i went wrong

select c.CompanyName,cd.FedTaxID,cd.EmailAddress,cd.PhoneNumber
from tblcustomerdetail cd,tblcustomer c 
where c.FedTaxID in (
      select FedTaxID 
      from tblcustomer 
      where CustomerID in (
           select LOginID 
           from tbluserlogindetail 
           where UserName like "pa%" and RoleTypeID='20'
                          )
                     )
and cd.FedTaxID in (
      select FedTaxID 
      from tblcustomer
      where CustomerID in (
           select LOginID 
           from tbluserlogindetail
           where UserName like "pa%" and RoleTypeID='20'
                          )
                   );

My relation is here

My 3 tables are `tbluserlogindetails, tblcustomerdetails and tblCustomer'

1) Initially i will get `Login ID` from `tblUserLoginDetail ` based on the `user name`. 

2) Next based on `LoginID` i will get `FedTaxID` from tblcustomerDetail`

3) Next based on 'FedTaxID' i will get the the required details from `tblcustomer'


SELECT 
    tblcustomer.CompanyName,
    tblcustomerdetail.FedTaxID,
    tblcustomerdetail.EmailAddress,
    tblcustomerdetail.PhoneNumber 

FROM tbluserlogindetail, tblcustomer, tblcustomerdetail
WHERE 
    tbluserlogindetail.LOginID = tblcustomer.CustomerID
    AND tblcustomer.FedTaxID = tblcustomerdetail.FedTaxID

    AND tbluserlogindetail.UserName LIKE 'pa%'
    AND tbluserlogindetail.RoleTypeID = '20'

Try something like this.

Subqueries have a slow perfomance.

MySQL - SELECT WHERE field IN (subquery) - Extremely slow why?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜