Stack Exchange
Join 2 mysql Tables SUM and COUNT based on text field
thanks in advance for your help on this !
I have 2 tables that I need to join based on 2 different SELECTs 
First Select:
SELECT
Agent, 
count( Online_playerdatabase_v2.First_Deposit_Date) as NumbFirstDeposits
FROM Online_playerdatabase_v2
WHERE Agent <>'Agent' AND Online_playerdatabase_v2.First_Deposit_Date BETWEEN '2015-12-01' AND '2015-12-31'
group by Agent



Output:
Agent       NumbFirstDeposits
john            49
No Agent        1
mike            9

Then another Select:
SELECT  
   Agent,
    COUNT(DISTINCT Online_customer_activity_v2.Customers) as ActivePlayers, 
    Truncate(sum(Online_customer_activity_v2.Real_Money),0) as RM, 
    Truncate(sum(Online_customer_activity_v2._Bonuses),0) as BO, 
    Truncate(sum(Online_customer_activity_v2.Total_Win_Loss),0) as GGR,
    Truncate(sum(`Online_customer_activity_v2`.`Total_Bets`),0) as BETS
FROM Online_customer_activity_v2
WHERE `Online_customer_activity_v2`.`Date` BETWEEN '2015-12-01' AND '2015-12-31'
AND Online_customer_activity_v2.Total_Bets>0
GROUP BY Agent

Output:
Agent       ActivePlayers   RM      BO      GGR BETS
john        73              63118   28538   64  1395799
No Agent    1               80      0   -   21      876
mike        24              209780  28464   20  7955633

I would like to have a Join of the 2 outputs as below:

Agent ActivePlayers RM      BO      GGR     BETS    NumbFirstDeposits
john            73  63118   28538   64      1395799 49
No Agent        1   80      0   -   21      876     1
mike            24  209780  28464   20      7955633 9


accept the suggested edit

which is the foreign key column?

You can try this,
SELECT Online_customer_activity_v2.Agent,
COUNT(DISTINCT Online_customer_activity_v2.Customers) as ActivePlayers, 
Truncate(sum(Online_customer_activity_v2.Real_Money),0) as RM, 
Truncate(sum(Online_customer_activity_v2._Bonuses),0) as BO, 
Truncate(sum(Online_customer_activity_v2.Total_Win_Loss),0) as GGR,
Truncate(sum(`Online_customer_activity_v2`.`Total_Bets`),0) as BETS,
count( Online_playerdatabase_v2.First_Deposit_Date) as NumbFirstDeposits FROM Online_customer_activity_v2 join Online_playerdatabase_v2 on Online_playerdatabase_v2.agent=Online_customer_activity_v2.agent WHERE `Online_customer_activity_v2`.`Date` BETWEEN '2015-12-01' AND '2015-12-31' AND Online_customer_activity_v2.Total_Bets>0 GROUP BY Online_customer_activity_v2.Agent


One way to do this without having to rewrite the queries is to use them both at derived tables like this:
select t1.*, t2.NumbFirstDeposits
from (<<your first query here>>) t1
join (<<your second query here>> t2 on t1.agent = t2.agent


Thanks Man. Quick and straightforward answer.

Try to apply join like this way:
SELECT ***your_column_names_here***
FROM Online_playerdatabase_v2 as  P
join Online_customer_activity_v2 as C on P.Agent=C.agent
WHERE
***conditions***
Group BY p.Agent

