Jump to content

[SOLVED] looking for assistance on pulling data from multiple tables


drranch

Recommended Posts

I would like to pull appointment dates from 4 different tables and display the appointments that are with in a certain time from. 

 

"SELECT * FROM show WHERE follow_up_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) ORDER BY follow_up_date DESC "

 

When I do a join i get the message...

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/testing/html/testscript.php on line 9

 

Here is the join script...

SELECT * FROM show, appointment WHERE show.username = appointment.username AND follow_up_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) ORDER BY follow_up_date DESC

 

 

 

 

OK...........

 

I figured it out.  Its very complicated to esplain ;) buuuuuuuuuut... since my tables had the same names I had to change the name of the fields in the query by using the AS statment. 

 

example...

 

select show_table.username, show_table.follow_up_date AS sttable, appointment_table.username, appointment.follow_up_date AS atfollow_up_date from show_table, appointment_table WHERE show_table.username = appointment_table.username...

 

I was also able to narrow down the query by using the BETWEEN statement to gather only a certain range of dates and using the DATE_ADD and DATE_SUB  Pretty cool stuff...........Having fun learning all this stufffffffffff

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.