Jump to content

JOIN HELP


jrobles

Recommended Posts

Im having a problem getting a sql statement to give me the data that i need. Here is my statement

 

SELECT 
Clients.ClientID, 
ClientProfile.FirstName,
ClientProfile.LastName, 
SUM(OrderAmount) AS TOTAL
FROM Clients
JOIN ClientProfile ON Clients.ClientID = ClientProfile.ClientID
LEFT JOIN OrderHeader ON Clients.ClientID = OrderHeader.ClientID
WHERE Clients.UserID =17

 

The code above only returns one Client row with the sum of all the rows in my orderheader table. I need each client listed with the sum of of their orders only in a table format i.e.

 

CLIENTID---FNAME---LNAME---TOTAL

4                John      Doe        57.87

5                Jane      Smith    24.25

6                Steve    Meh        14.85

 

Here is a brief description of what I am doing. I have sales associates that can have many clients, each client can have many orders. I need to report all the clients and their total sales for any given sales associate.

 

Link to comment
Share on other sites

Of course it only returns one row, you tell it too...

 

WHERE Clients.UserID =17

 

If the one row you are getting is correct for that user, just removeing the WHERE clause should give you the right values... Also what is the difference between Clients.ClientID and Clients.UserID

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.