Author Topic: SQL question  (Read 625 times)

Offline Quantz

  • Level 8
  • *
  • Posts: 36
  • Reputation: +0/-0
    • View Profile
SQL question
« on: March 20, 2011, 02:33:31 AM »
I have a question about a mysql query im having trouble with... Is it possible to select from a table for example

Code: [Select]
SELECT * FROM table_a WHERE timestamp<=timestamp+43200"
What I'm trying to do is check for any rows in a table that are 5 days or less old but I'm not sure if mysql lets you do this.

my actual code is here,

Code: [Select]
mysql_query("SELECT * FROM friendly_challenges WHERE challenger='$team_a[id]' AND accept='No' AND timestamp<=timestamp+432000");
Anyways, would appreciate any advice. I know a longer way to code around this, I would just like to know if there is syntax to actually do it like this.

Cheers,
Doug
-- Quantz

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: SQL question
« Reply #1 on: March 20, 2011, 02:39:21 AM »
For "or less" you need > not <

if you have a datime column then you can do
Code: [Select]
WHERE created > NOW() - INTERVAL 5 DAY
for timestamp, yes, something like than should work

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
...
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Quantz

  • Level 8
  • *
  • Posts: 36
  • Reputation: +0/-0
    • View Profile
Re: SQL question
« Reply #2 on: March 20, 2011, 04:08:26 AM »
heh, i figured it out

Code: [Select]
$fiveDays = $now-432000;
mysql_query("SELECT * FROM friendly_challenges WHERE challenger='$team_a[id]' AND accept='No' AND timestamp>='$fiveDays'");

that did the trick, thanks for helping me out!!!
-- Quantz

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal