I have a Mysql query that selects some columns from 2 tables with an inner join. it is supposed to count the "Y" values from one table column and rturn this count with a Group By.
This is my query:
SELECT (SELECT Count(tblinterview.Contacted) FROM tblinterview WHERE tblinterview.Contacted = "Y")
as Contact_Y , tbldata.RegionID, tbldata.BranchCode, tbldata.BranchDesc, tbldata.CampaignID, tblinterview.EndTime
FROM tbldata INNER JOIN tblinterview
WHERE tblinterview.DataID = tbldata.DataId
AND tblinterview.Complete = "Y"
GROUP BY tbldata.BranchCode, tbldata.RegionID, tblinterview.EndTime
By my result set is: Where all the Contact_Y are the total count of all records instead of a grouping count.
Contact_Y RegionID BranchCode BranchDesc CampaignID EndTime
1407 1 9725 Dada Motors 31 2012-01-26 12:51:12
1407 1 9725 Dada Motors 31 2012-01-31 10:25:18
1407 1 9725 Dada Motors 31 2012-02-01 11:30:37
1407 1 9725 Dada Motors 31 2012-02-01 14:48:57
1407 3 9732 Ballito Autohaus 37 2012-01-16 15:04:12
1407 3 9732 Ballito Autohaus 46 2012-01-18 11:59:53
1407 3 9732 Ballito Autohaus 31 2012-01-20 14:26:12
1407 3 9732 Ballito Autohaus 31 2012-01-20 16:05:48
Could someone explain where my query is wrong?