amites Posted January 27, 2008 Share Posted January 27, 2008 This one is kicking my butt, I am building a query with a join statement, the idea is that all rows with an entry within a certain range of another table entries, I know i can do this in a single query but I'm having trouble with it don't want to pull things out, build my range and then query again... anyway the code so far looks like: $query = "SELECT s.id, s.userid, s.msg_date, s.subject" . "\n FROM bil_msg_sent AS s" . "\n JOIN bil_msg_look AS l" . "\n WHERE s.locid = l.locid" . "\n AND s.msg_date BETWEEN **l.msg_date - 1 hour** AND **l.msg_date + 1 hour**"; obviously the parts in the ** are my comments describing what I want to do, any ideas? ??? Quote Link to comment https://forums.phpfreaks.com/topic/88016-solved-selecting-entry-from-mysql-based-on-date-range/ Share on other sites More sharing options...
toplay Posted January 27, 2008 Share Posted January 27, 2008 $query = "SELECT s.id, s.userid, s.msg_date, s.subject FROM bil_msg_sent AS s JOIN bil_msg_look AS l ON s.locid = l.locid WHERE s.msg_date BETWEEN l.msg_date - INTERVAL 1 hour AND l.msg_date + INTERVAL 1 hour "; Quote Link to comment https://forums.phpfreaks.com/topic/88016-solved-selecting-entry-from-mysql-based-on-date-range/#findComment-450333 Share on other sites More sharing options...
amites Posted January 29, 2008 Author Share Posted January 29, 2008 had to tinker with other parts of it, though your BETWEEN line worked perfectly many thanks Quote Link to comment https://forums.phpfreaks.com/topic/88016-solved-selecting-entry-from-mysql-based-on-date-range/#findComment-451881 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.