Jump to content

Problems with my MySQL query


Recommended Posts

Hello!

 

I have a following problem with my MySQL.

 

I have a one table called news, and inside that table I have a two colums called time and subject. Time is for example 14:53 and subject is normal string ..

 

If I would like to make a query which would retrieve last subjects from the last for example 10 minutes I have tried this query:

 

Select subject from news where aika between 'select time(current_timestamp)' and 'select time(now()-interval 10 minute)' but it gives me a zero result set .. I  think I cannot use that kind of "variables" to generate time , but How I am going to make that query then ?

 

Help needed!

 

Petri

 

 

Link to comment
Share on other sites

  • 4 weeks later...

Are you storing you time as a timestamp or as a string like "14:53"? Also what language are you working in?

 

I am mostly a PHP guy so I would do it like this (not saying this code will work but it will hopefully help point you in the right direction):

$current = time();
$currentLessTen = $current - 600;
$query = 'SELECT subject FROM news WHERE time BETWEEN ' . $currentLessTen . ' AND ' . $current . ' ORDER BY time DESC';

 

"ORDER BY time DESC" assumes you want the results listed from newest to oldest.

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.