Hi, I have three tables like this
handhelds_table
aid hid handheld_type enable
1 1 Casio Y
1 2 Casio Y
2 3 Ipaq Y
2 4 Ipaq Y
3 5 Motorola Y
3 6 Motorola Y
company_details
aid company_name
1 Bloggs Ltd
2 Bent Ltd
3 Turner Ltd
maintenance_table
aid maintenance_type
1 Handhelds
2 Software
3 Handhelds and Software
all three tables are linked via 'aid'
Now I can run a query to get the quanties of each handheld type for each company using this query:
SELECT company_name AS Company Name , handhelds.handheld_type AS Handheld Type , count( * ) AS Number
FROM handhelds
JOIN company_details ON handhelds.aid = company_details.aid
WHERE handhelds.enable = 'Y'
GROUP BY company_name , handheld_type
ORDER BY company_name ;
But when ever I join the maintenance table into the query like this:
SELECT company_name AS Company Name , handhelds.handheld_type AS Handheld Type , count( * ) AS Number , maintenance.maintenance_type AS 'Maintenance Type'
FROM handhelds
JOIN maintenance ON handhelds.aid = maintenance.aid
JOIN company_details ON handhelds.aid = company_details.aid
WHERE handhelds.enable = 'Y'
GROUP BY company_name , handheld_type
ORDER BY company_name ;
The count goes silly so if Bloggs Ltd had 67 Casio's the query outputs 670 Casio's.
Where am I going wrong?
Thanks for any help.
Rich