F
Francois
Hi, I need some help with a Microsoft Access query that I have been trying
to get working all day. Here is the scenario. The example below is a
contrived "car-parts" one. The real system is for a report in a Haberdashery
order entry system.
In my simplified example, I have is three tables.
Table 1: Car
Field 1: CarID, number
Table 2: Radio
Field 1: CarID,number 'the Car ID in the Car table
Field 2: RadioName,text 'The Radio name
Field 3: Red,number 'either 1 or 0
Field 4: Blue,number 'either 1 or 0
Field 5: Green,number 'either 1 or 0
Field 6: Black,number 'either 1 or 0
Table 3: Seat
Field 1: CarID,number 'the Car ID in the Car table
Field 2: SeatName,text 'The Seat name
Field 3: Red,number 'either 1 or 0
Field 4: Blue,number 'either 1 or 0
Field 5: Green,number 'either 1 or 0
Field 6: Black,number 'either 1 or 0
In English, what I want is to perform a database query to count the all the
car IDs that have the count of
Seat.Red+Seat.Blue+Seat.Green+Seat.Black+Radio.Red+Radio.Blue+Radio.Green+Radio.Black
= to a certain number, say 3 or 4 or 5 or 6 or whatever, I will change this
in my VBA code as required.
I have been working on a query like this. This works!
SELECT COUNT(Car.CarID)
FROM Car,
Radio
WHERE Car.CarID=Radio.CarID
HAVING Radio.Red+Radio.Blue+Radio.Green+Radio.Black=3
But, it isn't really what I want. But I am close. I want it to count the
number of CAR IDs where
Radio.Red+Radio.Blue+Radio.Green+Radio.Black+Seat.Red+Seat.Blue+Seat.Green+Seat.Black=3
but the following won't work
SELECT COUNT(Car.CarID)
FROM Car,
Radio,
Seat
WHERE Car.CarID=Radio.CarID
AND Car.CarID=Seat.CarID
HAVING
Radio.Red+Radio.Blue+Radio.Green+Radio.Black+Seat.Red+Seat.Blue+Seat.Green+Seat.Black=3
because, although there is always a Car.CarID, there is sometimes only a
corresponding CarID in the Seats table, sometimes there is a only a
corresponding CarID in the Radio table, sometimes there is neither, and
sometimes there is both. The query above only works when there are both, I
want it to work in all situations.
I know this has something to do with outer joins but I can't work out the
syntax and when I attempt to use the design tool in Access, is creates this
big really overcomplicated messy query that I can't work out. I am using
Access 2000 and Access 97.
Thank you for your help.
Francois
to get working all day. Here is the scenario. The example below is a
contrived "car-parts" one. The real system is for a report in a Haberdashery
order entry system.
In my simplified example, I have is three tables.
Table 1: Car
Field 1: CarID, number
Table 2: Radio
Field 1: CarID,number 'the Car ID in the Car table
Field 2: RadioName,text 'The Radio name
Field 3: Red,number 'either 1 or 0
Field 4: Blue,number 'either 1 or 0
Field 5: Green,number 'either 1 or 0
Field 6: Black,number 'either 1 or 0
Table 3: Seat
Field 1: CarID,number 'the Car ID in the Car table
Field 2: SeatName,text 'The Seat name
Field 3: Red,number 'either 1 or 0
Field 4: Blue,number 'either 1 or 0
Field 5: Green,number 'either 1 or 0
Field 6: Black,number 'either 1 or 0
In English, what I want is to perform a database query to count the all the
car IDs that have the count of
Seat.Red+Seat.Blue+Seat.Green+Seat.Black+Radio.Red+Radio.Blue+Radio.Green+Radio.Black
= to a certain number, say 3 or 4 or 5 or 6 or whatever, I will change this
in my VBA code as required.
I have been working on a query like this. This works!
SELECT COUNT(Car.CarID)
FROM Car,
Radio
WHERE Car.CarID=Radio.CarID
HAVING Radio.Red+Radio.Blue+Radio.Green+Radio.Black=3
But, it isn't really what I want. But I am close. I want it to count the
number of CAR IDs where
Radio.Red+Radio.Blue+Radio.Green+Radio.Black+Seat.Red+Seat.Blue+Seat.Green+Seat.Black=3
but the following won't work
SELECT COUNT(Car.CarID)
FROM Car,
Radio,
Seat
WHERE Car.CarID=Radio.CarID
AND Car.CarID=Seat.CarID
HAVING
Radio.Red+Radio.Blue+Radio.Green+Radio.Black+Seat.Red+Seat.Blue+Seat.Green+Seat.Black=3
because, although there is always a Car.CarID, there is sometimes only a
corresponding CarID in the Seats table, sometimes there is a only a
corresponding CarID in the Radio table, sometimes there is neither, and
sometimes there is both. The query above only works when there are both, I
want it to work in all situations.
I know this has something to do with outer joins but I can't work out the
syntax and when I attempt to use the design tool in Access, is creates this
big really overcomplicated messy query that I can't work out. I am using
Access 2000 and Access 97.
Thank you for your help.
Francois