I have two tables
Registry
ClientID Name Incube
----------------------
1 Joe as
2 Jack gt
3 Jor ee
Deposit
DepositID ClientID Quantum
----------------------------
1 1 100.45
2 1 34.5
3 1 22.0
4 2 1000.0
I want to get only one result, this is
The Name, Incube from table Registry and the sum of all deposits made by that person all corresponfing to a certain ClientID
First I was doing 2 queries
SELECT [Name],[Incube] FROM Registry WHERE [ClientID] = 1;
SELECT DISTINCTROW Sum([Deposit].[Quantum]) As Total FROM Deposit WHERE [ClienteID] = 1;
then I did a left join to get all things more easy
SELECT
[a].[ClientID],
[a].[Name],
[a].[Incube],
Sum([b].[Quantum]) as Total
FROM Registry a
LEFT JOIN Deposit b
ON a.ClientID=b.ClientID
group by a.Name, a.ClientID, a.Incube;
How do I filter de WHERE clause? I want to get all data of ClientID=1, NOT ALL, And the question here is how to only compute only the necessary ClientID and not all the clientsID?
Unless I am missing something you just need to add the
WHEREclause:See SQL Fiddle with Demo
The result is: