I have a database in Access that has the following tables:
Table Options
Columns:
- Id_Option int
- Option varchar (50)
- Status (bit)
Contains these data:
Table Votes
Columns:
- Vote_ID int
- Id_Option int
- Date Date Time
What I need to build a query that gets the amount of votes that each option has in a date range .
For example, if I select a range of dates between 01/08/2016 and 08/31/2016 , you should get a value similar to the following:
This is the query I use:
SELECT Opc.Opcion, (SELECT COUNT(Vts1.Id_Respuesta)
FROM Votos AS Vts1) AS [Votos],
Vts.Fecha
FROM Opcion AS Opc INNER JOIN Votos AS Vts
ON Opc.Id_Opcion = Vts.Id_Opcion
WHERE Opc.Estado = True
ORDER BY Vts.Fecha;
WHERE Opc.Estado = True AND
(Vts.Fecha BETWEEN #01/08/2016 00:00# AND #31/08/2016 23:59#)
ORDER BY Vts.Fecha;
But the results do not match what was expected, also, if there are zero votes, sometimes I get this error:
at most one record can be returned by this subquery
How should the query be modified to generate the expected results?