Jump to content

Need Help formulating a Query


vincej

Recommended Posts

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

Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

 

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 !

Link to comment
Share on other sites

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.

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.