I'm using MySql 5.5.
I need to find a userid on a date with a particular ip address.
The fields are userid, ipaddress, startdate, enddate.
So for instance I am looking for a userid with ip address 192.168.1.1 on Sep 12 2011.
the query would be similar
select * from database where ipaddress='192.168.1.1' and 2011-12-09 is in(startdate and enddate);
Any help to pointing out this logic flaw is welcome. Thank you.
the obvious solution would be like:
but theres a shortcut using
BETWEEN
so you can simply write:note:
BETWEEN
also works for numbers, strings and other stuff, and it's possible to negate it by writingNOT BETWEEN
- quite useful sometimes.It's not very clear if you want:
or:
Since there is a start and end date, maybe something along the line of:
Or as pointed out by ypercube you can use
BETWEEN
: