vincej Posted March 11, 2012 Share Posted March 11, 2012 Hi - Lets start with a sample of my table: pickupid pickuplocation Date1 Date2 Date3 Date4 1 Collingwood 1328079600 1330585200 1333260000 1335852000 2 Varsity 1328079600 1330585200 1333260000 1335852000 3 Canmore 1328079600 1330585200 1333260000 1335852000 4 Westbrook 1328079600 1330585200 1333260000 1335852000 I need a query which will select only those dates which are in the future. If a date is in the past the query must skip over it. I have tried using Select with Have, Or, Where & AND. My queries fail because if one of the dates happens to be in the past then the whole query comes back with zero results. Yes, I know that if I orientated my table around the other way ie with locations in the columns and dates in the rows it could make it easier - I've tried that, but I run into other problems as my HTML report has to accommodate over 50 locations, but only 4 dates. Many Many Thanks for All your Help !! MYSql 5.5.16 Quote Link to comment Share on other sites More sharing options...
cpd Posted March 11, 2012 Share Posted March 11, 2012 "SELECT * FROM tblName WHERE Date1 > ".time()." AND Date2 > ".time()." AND Date3 > ".time()." AND Date4 > ".time() That will select anything greater than the current second in time but I'm not sure if you want to skip over the current date. That should fix it up. I'm sure there's a better way to do it but in my tired state I can't think of anything. Quote Link to comment Share on other sites More sharing options...
vincej Posted March 11, 2012 Author Share Posted March 11, 2012 Thanks CPD .. I did try using AND, but the problem is that the query will not skip over a value and go to the next value. By chaining together a collection of AND statements if only on eof those statements fails then the whole query fails. Many Thanks ! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 11, 2012 Share Posted March 11, 2012 You shouldn't have multiple dates (pieces of same meaning data) spread out in columns in each row. It makes any query more complicated. Your table should only have columns for the id, location, and date. You would have multiple rows for each location and a query to get just the rows with dates in the future would be simple. Quote Link to comment 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.