Hello,
I have a specific row in my database, with the following information:
data:
user_id start_time end_time
405 12:00:00 14:00:00
I have the following SELECT statement:
SELECT *
FROM data
INNER join users on users.user_id = data.user_id
WHERE NOT EXISTS
(SELECT * FROM data
WHERE '10:00:00' BETWEEN start_time AND end_time)
GROUP BY users.usrID");
Now, I would think that this query would return the above row (user 405), however, it does not return anybody. (Because 10:00:00 is not between 12:00:00 and 14:00:00).
Interestingly, if I change the value 10:00:00 to 07:00:00, it works fine.
Any ideas on why this is not working? In the database, I have the fields set up as TIME, and they're formatted as such: 00:00:00
Thanks very much!
Update:
I changed my query around to look like this:
SELECT usrID,
first,
last
FROM users
WHERE user_id NOT IN (SELECT u.user_id
FROM `data` d,
`users` u
WHERE d.user_id = u.user_id
AND CAST('10:00:00' AS TIME) BETWEEN start_time AND end_time)
ORDER BY u.user_id
And this seemed to do the trick. Thanks for all the help.