Mysql – How to get dates from a table while the date range is from the date belonging to another table

MySQLmysql-workbenchquery

I have a table datedim which has all the dates of a month in it. I have another table attendance that has dates on which attendance were taken. I need to write a query where i can get all the dates from the start till current.
For eg. if attendance table has records starting from 3-Apr-2019 to 3-June-2019, i should get all the dates in between them.

Best Answer

You can use the BETWEEN conditional operator to search for anything in a range. The BETWEEN operater is inclusive so will find records for the start and end dates too.

You will be able to query the attendance table directly:

SELECT * FROM attendance WHERE attendancedate BETWEEN '2019-04-03' AND '2019-06-03'

This question has some examples: https://stackoverflow.com/questions/3822648/how-do-i-query-between-two-dates-using-mysql

I hope that helps!