Skip to main content
Inspiring
August 7, 2008
Question

Query of Query

  • August 7, 2008
  • 1 reply
  • 625 views
I'm trying to figure out how, once I have selected a record, to query the 3 previous records in the same table. I'm using MySql 5.0 and for a reference point the Primary Key is ID.

Any help is appreciated!
David
This topic has been closed for replies.

1 reply

Inspiring
August 8, 2008
It's not a query of queries. Google "mysql top n" and you'll get some ideas.
InkfastAuthor
Inspiring
August 8, 2008
OK I see what your saying, I guess that really wasn't what I needed. Thanks for that tip though!

What if I created a query in which the where clauses determined the starting row based on 2 fields and then included a certain number of rows beneath? (Using MySql db)
Inspiring
August 8, 2008
Inkfast wrote:
> What if I created a query in which the where clauses determined the starting row based
> on 2 fields and then included a certain number of rows beneath? (Using MySql db)

MySQL does not not have a built-in row number concept. However, as mentioned, you could certainly order the results and return the first x number of records using LIMIT

> I'm trying to figure out how, once I have selected a record, to query the 3 previous
> records in the same table....
> I guess that really wasn't what I needed

If LIMIT does not do what you need, then I suspect your goal is different or more complicated than you have described.