MySQL Forums
Forum List  »  General

Re: Circular queue query
Posted by: Felix Geerinckx
Date: April 18, 2005 05:07AM

Ashwin Kamath wrote:

> I have stored a circular queue in the database table
> as shown.
> ...
> I need to find a query which will return me the next user for a given user id

I would implement a circular queue as follows:

CREATE TABLE circular_queue (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL UNIQUE,
next_user_id INT NOT NULL UNIQUE
);

so finding the next user is trivial:

SELECT next_user_id FROM circular_queue WHERE user_id = <<user_id>>

Depending on your requirements, you could even add a prev_user_id column.

--
felix

Options: ReplyQuote


Subject
Written By
Posted
April 18, 2005 02:30AM
Re: Circular queue query
April 18, 2005 05:07AM
April 18, 2005 05:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.