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!

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

 

 

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?

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.