Search code examples
sqlmysqldatabase

How to get the data from MYSQL database for a particular date where there is no record


I have a MYSQL database where data is stored for particular users.The database also records the date and time when the user has inserted the data. I want to query and check if the user has not inserted any data for the previous dates. i.e. I want to know if the user has not inserted any data on a particular date and get that date for which no data has been inserted.Is it possible to get the date in that manner? I am trying the below query but it doesn't work.

SELECT date from employee_details where date < NOW() && date IS NULL;

Solution

  • If no data exists in employee_details for the give date (i.e. the user has done nothing on the given date) your query will not return anything.

    You may create a separate table containing nothing but dates and use this to do an outer join to determine if no user data exists for the give day.