Jump to content

[SOLVED] Selecting entry from mySQL based on date range


Recommended Posts

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?  ???

$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

            ";

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.