dk4210 Posted September 30, 2011 Share Posted September 30, 2011 Hello Guys, I have a question.. I am trying to query the data base for a specific date range but it's not displaying the correct date range.. Here is my query SELECT * FROM report WHERE start_date AND end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00' It seems to be loading all the rows not just the date rage specified above.. Please advise.. Thanks, Dan Quote Link to comment https://forums.phpfreaks.com/topic/248179-query-by-date-range/ Share on other sites More sharing options...
ManiacDan Posted September 30, 2011 Share Posted September 30, 2011 SELECT * FROM report WHERE (start_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') AND (end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') -Dan Quote Link to comment https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274395 Share on other sites More sharing options...
dk4210 Posted September 30, 2011 Author Share Posted September 30, 2011 On more question for ya.. Is there a way to construct a query to grab the date range about and combine it with another table for example if I had two tables Table A |id |listing_id| start_date | end_date| Table B | listing id | listing_name | What I would like to do is query table A for * with start and end date and get the id Create a second query to grab the listing name in table b Combine the query results to show is the listing name in the csv file that I will be exporting... Did I lose you? Thanks for your help.. Quote Link to comment https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274405 Share on other sites More sharing options...
Muddy_Funster Posted September 30, 2011 Share Posted September 30, 2011 yeah, you did, why don't you just JOIN the tables on listing_id? Quote Link to comment https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274430 Share on other sites More sharing options...
ManiacDan Posted September 30, 2011 Share Posted September 30, 2011 Never use queries in a loop, always use a JOIN. SELECT table_b.listing_id, listing_name, start_date, end_date FROM Table_a join table_b on table_a.listing_id = table_b.listing_id WHERE (start_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') AND (end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') -Dan Quote Link to comment https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274433 Share on other sites More sharing options...
dk4210 Posted September 30, 2011 Author Share Posted September 30, 2011 Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274435 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.