0

here is the table example


main_CD code
1 aa

1 bb

1 cc

2 1231

2 1232

.

that table have lots of data. but i will only use which main_CD is "1" (other data for other pages I cannot delete it)

my question is that If i got value of "cc". I want to sent pre_data ("aa") and next data ("cc")

also if i got value of "cc", pre_data would be "bb" and next_data would be "aa"

darly
  • 1
  • 3
  • 3
    You need a column in the table that tells you what row comes before the another row. Do you have that? – Mikael Eriksson Dec 16 '14 at 10:56
  • 1
    You say you want a stored procedure (for some reason). Which dbms are you using? (Many different stored procedure flavors out there...) – jarlh Dec 16 '14 at 10:56
  • Use the `lag()` and `lead()` functions –  Dec 16 '14 at 10:56
  • 2
    How do you know that aa is before bb and that cc is after bb? It looks that way to us as humans, but in a database the order of rows is not determined unless you define it explicitly. Are there columns that you've not mentioned? – Rikalous Dec 16 '14 at 11:08
  • What RDBMS are you using? – Mureinik Jan 06 '15 at 06:21

0 Answers0