MySQL Forums
Forum List  »  MySQL Query Browser

select previous and next row
Posted by: Gabriel Quagliano
Date: February 14, 2007 11:11PM

hi!

i've a problem designing a query. i need to select a specific row (no problem with that) and then select the previous and the next topics that matches with some conditions, but i dont know how. for example:

i select a row from my table with the query:
SELECT * FROM tabla WHERE id=3 AND author='yo' AND category='noticias'

and then i want to select the previous and the next row that match with this:
WHERE author='yo' AND category='noticias'

maybe i can explain better.. my table is like this (just example)

+----+--------+----------+------------+
| id | nota | author | category |
+----+--------+----------+------------+
| 1 | nota1 | yo | noticias |
| 1 | nota2 | geq | patata |
| 2 | nota3 | yo | posts |
| 3 | nota4 | yo | noticias |
| 1 | nota5 | perez | mio |
| 3 | nota6 | geq | patata |
| 4 | nota7 | yo | posts |
| 5 | nota8 | yo | noticias |
+----+--------+----------+------------+

if i select the row of 'nota4' i want to know wich are the inmediatly previous and inmediatly next that matches with autor='yo' and category='noticias', in this case retreiving the rows of 'nota1' and 'nota8'

someone told me about the EXIST directive, but i have MySQL 4.0.25 and it is not supported!!

well i hope you will understand

thank you!
and best regards

Options: ReplyQuote


Subject
Written By
Posted
select previous and next row
February 14, 2007 11:11PM
February 14, 2007 11:37PM
January 01, 2008 06:45AM
November 24, 2007 10:33PM


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.