4

I'd like to know how to how to make a query that does this:

I have a table like this:

CREATE TABLE `sendingServers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `address` text NOT NULL,
  `token` text NOT NULL,
  `lastPoll` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

And I'd like to get the following:

  • Select all servers where lastPoll is less then X seconds ago
  • Then select a random entry from the return value

Is this possible ? How do I achieve that ?

0

1 Answer 1

4

You can use something like this:

select * from `sendingServers`
where  `lastPoll` > DATE_SUB(NOW(), INTERVAL 30 SECOND) 
order by rand() limit 1
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.