Jump to content

Querying Events From MySQL db, in 2 tables


mb1

Recommended Posts

Hi,

 

I am querying events for "today". So I have this code:

$query3 ="SELECT * FROM `mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY)";

 

It works ok (if there is a better way to do this, feel free to let me know). But then I also need to pull data from a different table. So I added the other query but somehow it is triggering an error. Not sure what could be wrong, could you please help me?

 

Here is the code that's triggering an error:

$query3 ="SELECT * FROM `mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY), `mb_foursquare`.`venues` WHERE eventsbydate.v_id = venues.v_id";

 

Thank you!

Link to comment
Share on other sites

Thank you. That's only because i am querying 2 tables.

 

I have this on one side:

`mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY)

 

And this on the other side:

`mb_foursquare`.`venues` WHERE eventsbydate.v_id = venues.v_id

 

 

Link to comment
Share on other sites

Look into a LEFT JOIN.

 

I'm not exactly sure what you're looking to do, but here's an example of a left join:

 

SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

Link to comment
Share on other sites

Thank you again. Let me be a little more specific about what i want to do: I am selecting from my event table (eventsbydate) all the events that are happening today. Then I am also pulling data on all the venues from a different table (venues).

 

I tried this and it is still triggering an error... :(

 

SELECT * FROM `mb_foursquare`.`eventsbydate` 
WHERE `mb_foursquare`.`eventsbydate`.`datetime1` 
BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY) 
LEFT JOIN `mb_foursquare`.`venues` ON eventsbydate.v_id = venues.v_id

 

Any idea what the issue could be?

 

Link to comment
Share on other sites

sorry i didn't reply back - long weekend - but not long enough to do too much on the computer. :)

 

I'll look a bit more into it, and get back to ya today. (unless someone else chimes in, too).

 

T

Link to comment
Share on other sites

Thank you. Actually, I figured it out!

 

SELECT * FROM `mb_foursquare`.`eventsbydate`, `mb_foursquare`.`venues` WHERE DATE(datetime1) = DATE(CURDATE()) AND eventsbydate.v_id = venues.v_id

 

I had to put the FROM table 1, table 2 at the very beginning. and attach the WHENs with an AND.

Link to comment
Share on other sites

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.