C
CDF
Hi,
I'm having trouble working out the following.
I've got 2 tables (tbl_Customer & tbl_Vehicle) linked by a Customer_ID
field with a 1:Many relationship (1 customer (Customer_ID (PK)) can
have many vehicles (Customer_ID (Fk))).
I have the following query which show a count of my Vehicle_ID and
Customer_ID
SELECT tbl_Vehicle.Vehicle_ID, tbl_Vehicle.Customer_ID, Count
(tbl_Vehicle.Vehicle_ID) AS CountOfVehicle_ID, Count
(tbl_Vehicle.Customer_ID) AS CountOfCustomer_ID
FROM tbl_Customers INNER JOIN tbl_Vehicle ON tbl_Customers.Customer_ID
= tbl_Vehicle.Customer_ID
GROUP BY tbl_Vehicle.Vehicle_ID, tbl_Vehicle.Customer_ID;
It spits out the following:
Vehicle_ID Customer_ID CountOfVehicle_ID CountOfCustomer_ID
17 1 1 1
23 1 1 1
24 6 1 1
30 6 1 1
34 8 1 1
36 8 1 1
46 8 1 1
48 8 1 1
49 8 1 1
As you can see I would like it to count 9 vehicles and 3 Customers.
I'm sure I'm going about it the wrong way!!
The reason for needing this is that I have a startup Form acting as a
Main Menu with a Customer Tab and a Vehicles Tab. On the customer tab
I'd like to show "x customers in database" on the Vehicle tab I'd like
to show "x vehicles in database".
As the form can only run from one query, I can't add my two single
table queries of:
Customer:
SELECT tbl_Customers.Customer_ID, Count(tbl_Customers.Customer_ID) AS
CountOfCustomer_ID
FROM tbl_Customers
GROUP BY tbl_Customers.Customer_ID;
and
Vehicle:
SELECT tbl_Vehicle.Vehicle_ID, Count(tbl_Vehicle.Vehicle_ID) AS
CountOfVehicle_ID
FROM tbl_Vehicle
GROUP BY tbl_Vehicle.Vehicle_ID;
Am I meant to do some sort of subquery or Select Distinct query in my
initial statement above or am I supposed to do something completely
different??
Thanks for any help.
I'm having trouble working out the following.
I've got 2 tables (tbl_Customer & tbl_Vehicle) linked by a Customer_ID
field with a 1:Many relationship (1 customer (Customer_ID (PK)) can
have many vehicles (Customer_ID (Fk))).
I have the following query which show a count of my Vehicle_ID and
Customer_ID
SELECT tbl_Vehicle.Vehicle_ID, tbl_Vehicle.Customer_ID, Count
(tbl_Vehicle.Vehicle_ID) AS CountOfVehicle_ID, Count
(tbl_Vehicle.Customer_ID) AS CountOfCustomer_ID
FROM tbl_Customers INNER JOIN tbl_Vehicle ON tbl_Customers.Customer_ID
= tbl_Vehicle.Customer_ID
GROUP BY tbl_Vehicle.Vehicle_ID, tbl_Vehicle.Customer_ID;
It spits out the following:
Vehicle_ID Customer_ID CountOfVehicle_ID CountOfCustomer_ID
17 1 1 1
23 1 1 1
24 6 1 1
30 6 1 1
34 8 1 1
36 8 1 1
46 8 1 1
48 8 1 1
49 8 1 1
As you can see I would like it to count 9 vehicles and 3 Customers.
I'm sure I'm going about it the wrong way!!
The reason for needing this is that I have a startup Form acting as a
Main Menu with a Customer Tab and a Vehicles Tab. On the customer tab
I'd like to show "x customers in database" on the Vehicle tab I'd like
to show "x vehicles in database".
As the form can only run from one query, I can't add my two single
table queries of:
Customer:
SELECT tbl_Customers.Customer_ID, Count(tbl_Customers.Customer_ID) AS
CountOfCustomer_ID
FROM tbl_Customers
GROUP BY tbl_Customers.Customer_ID;
and
Vehicle:
SELECT tbl_Vehicle.Vehicle_ID, Count(tbl_Vehicle.Vehicle_ID) AS
CountOfVehicle_ID
FROM tbl_Vehicle
GROUP BY tbl_Vehicle.Vehicle_ID;
Am I meant to do some sort of subquery or Select Distinct query in my
initial statement above or am I supposed to do something completely
different??
Thanks for any help.