Sql join question

Dark0Prince

Active Member
Joined
Feb 17, 2016
Messages
433
So below is my SQL query, but when I add the client.name it pulls every client in the system instead of just the one that has the one account i'm searching for in it. Is there a way to join one table to another to show me just the client's name on that one account?

Rich (BB code):
Select
DCGI.Client,
DCGI.Account_Num1,
DCGI.Date_Listed,
DGI.Last_Name,
DGI.First_Name,
DGI.Rp_Last_Name,
DGI.Rp_First_Name,
DGI.Address_Line_1,
DGI.Address_Line_2,
DGI.City,
DGI.State,
DGI.Zip_Code,
PH.Pay_Date,
PH.Occurence_Date,
PH.Amt_Applied,
PH.Bal_Before_Tran,
PH.Bal_After_Trans,
DS.Paid_In_Full_Date,
CG.CLIENT_NAME,
PIFR.PIF_CB_DEL_REQU

From
Dbtr_Clnt_Generl_Inf DCGI
LEFT JOIN Dbtr_General_Inf DGI ON DCGI.Account_Num1=DGI.Account_NUM1
LEFT JOIN Clnt_General CG ON DCGI.Client=DCGI.Client
LEFT JOIN Payment_History PH ON DCGI.Account_Num1=PH.Account_NUM
LEFT JOIN Dbtr_Status DS ON DCGI.Account_NUM1=DS.ACCOUNT_NUM1
LEFT JOIN DU_PAID_IN_FULL_REQUEST PIFR on PIFR.Account_Num1=DGI.Account_Num1

WHERE  
DCGI.Client = ?
And
DCGI.ACCOUNT_NUM1 = ?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You have:
LEFT JOIN Clnt_General CG ON DCGI.Client=DCGI.Client

Did you mean:
LEFT JOIN Clnt_General CG ON DCGI.Client=CG.Client
 
Upvote 0
So you're saying that table [Clnt_General] does not have a field named [Client] to join on?

to me this
DCGI.Client=DCGI.Client

indicates that you want all records where the table [DCGI] field [Client] equals itself. ie. all records.

Am I reading this wrong?
 
Upvote 0
So you're saying that table [Clnt_General] does not have a field named [Client] to join on?

to me this
DCGI.Client=DCGI.Client

indicates that you want all records where the table [DCGI] field [Client] equals itself. ie. all records.

Am I reading this wrong?


You are reading it right, but when I use "LEFT JOIN Clnt_General CG ON DCGI.Client=CG.Client" then it doesn't find CG.Client
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top