jbalanski Posted October 10, 2006 Share Posted October 10, 2006 HiI have a table with 12 "expiry date: columns for different tickets. How can I do a query that would select all the expiry date columns that would include all dates less than today and also include 90 days in the future. I can't use multiple ANDS or OR's any suggestions?The following is my query as it goes through the query as I add and statements there is no data. The first statement after where brings back 50 rows if I add the second it then drops to 10 and so on.........hopefully this makes sense.SELECTusers.lname,users.fname,users.positionappfor,users.hdsaliveexp,users.firstaidexp,users.fallproexp,users.whimisexo,users.regrescueexp,users.pitsexp,users.defdriveexp,users.otherexp,users.bopexp,users.boilerexp,users.confinedexp,users.loaderforkliftexp,users.jpickerboomerexp,users.boplineexp,users.tdgexp,users.detflameexp,users.driveexpire,users.driversabstract,users.drivedemeritFROMusersWHERE(users.hdsaliveexp < date_sub(now(), interval -90 day)) AND(users.firstaidexp < date_sub(now(), interval -90 day)) AND(users.fallproexp < date_sub(now(), interval -90 day)) AND(users.whimisexo < date_sub(now(), interval -90 day)) AND(users.regrescueexp < date_sub(now(), interval -90 day)) AND(users.pitsexp < date_sub(now(), interval -90 day)) AND(users.defdriveexp < date_sub(now(), interval -90 day)) AND(users.otherexp < date_sub(now(), interval -90 day)) AND(users.bopexp < date_sub(now(), interval -90 day)) AND(users.boilerexp < date_sub(now(), interval -90 day)) AND(users.confinedexp < date_sub(now(), interval -90 day)) AND(users.loaderforkliftexp < date_sub(now(), interval -90 day)) AND(users.jpickerboomerexp < date_sub(now(), interval -90 day)) AND(users.boplineexp < date_sub(now(), interval -90 day)) AND(users.tdgexp < date_sub(now(), interval -90 day)) Quote Link to comment Share on other sites More sharing options...
fenway Posted October 10, 2006 Share Posted October 10, 2006 That's an ugly looking query... you really should break these out into a separate table so that you can just have a single WHERE clause. Otherwise, it's going to get even uglier, because you'll need ORs, and then find out which one was the match. Quote Link to comment Share on other sites More sharing options...
jbalanski Posted October 10, 2006 Author Share Posted October 10, 2006 I thought of doing seperate tables but I am just trying to do a report that selects all the users with the following expiry dates that are less then today or will expire within 90 days. If user one only has one expiry date he will show up if he has 2 expiry dates those dates and only those will show up if user 2 has 5 expiry dates I will see those and so on. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 10, 2006 Share Posted October 10, 2006 So what? If each expiry date / item pair was a record, this would be a most trivial query. Quote Link to comment Share on other sites More sharing options...
jbalanski Posted October 12, 2006 Author Share Posted October 12, 2006 Maybe I am not making myself clear. (Maybe I am complicating it)I have a form with 16 date fields these are expiry dates for various certificates.We can do a query that will select the appropriate data ie any dates less than today and 90 days in the future.What ends up happening as you know is you get the user with 16 colums of dates with the one or two results from the query and the rest with dates that are over 90 days.I created a seperate table with userid expirydate and such but then adding via the form is difficult.Is there a way to highlight the query results in php so that if I get the user and the 16 date colums is it possible to highlight those results ie be it bold or a different color so they are easily seen. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 12, 2006 Share Posted October 12, 2006 Why would adding via the form be "difficult"? I think having 16 columns to query is much more difficult. Quote Link to comment Share on other sites More sharing options...
jbalanski Posted October 12, 2006 Author Share Posted October 12, 2006 Could you explain further Quote Link to comment Share on other sites More sharing options...
fenway Posted October 12, 2006 Share Posted October 12, 2006 Why not have a table of expiry_items, with a link back to user_id, that contains the item type (e.g. bop, boiler), the expiry date, and the FK? This would make queries very, very simple, and keep your DB normalized. 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.