Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Join Based on Date

Is it possible to join two tables based on the same date, not factoring in time?

Something like:

...FROM appointments LEFT JOIN sales ON appointments.date = sales.date...

The only problem is it is a datetime field, so I want to make sure it is only looking at the date and ignoring time

like image 933
kilrizzy Avatar asked Oct 21 '09 15:10

kilrizzy


1 Answers

You can do it like this:

FROM appointments
LEFT JOIN sales ON DATE(appointments.date) = DATE(sales.date)

But I'm pretty sure it won't be able to use an index, so will be very slow.

You might be better off adding a date column to each table.

like image 139
Greg Avatar answered Oct 18 '22 07:10

Greg