How to write such select:
SELECT filename, username, date_time, field1, field2... FROM... JOIN... WHERE...
UNLESS user_downloaded_this_file_today_already
I would like to ignore files downloaded by the same user on the same day. Data example:
12 | file1.jpg | barney | 2012-03-15 12:50:10 | ...
13 | file1.jpg | roger | 2012-03-15 13:50:10 | ...
14 | file2.jpg | barney | 2012-03-15 14:50:10 | ...
15 | file1.jpg | barney | 2012-03-15 15:50:10 | ...
How do I write a SELECT that would ignore 4th line? Same filename, same user, day difference < 1. Is this actually possible?
Simply use
SELECT DISTINCT(assuming you don’t need the numeric column since it’s not in your select):If your
Date_Timecolumn contains times and not just00:00:00, you’ll need to strip out the time forDISTINCTto work properly:Here’s an example of the date stripping in action.