writing SQL queries to get neighbour rows -
writing SQL queries to get neighbour rows -
i have come across problems writing queries getting neighbour rows , have no thought it.
this scenario (it not purely implemented using sql @ moment, rather mix of sql , java implementation) :
there entity has 1000 entity b, each entity b has 1000 entity c, each entity c has 1000 entity d. need utilize info stored in d. @ first have query entity ds within entity a. implement logic can navigate particular d next d or previous d, logic not written sql queries.
question 1
if want implement navigation logic sql queries, how can go next d in select query? suppose original query simple
select * d inner bring together c c.id = d.fk inner bring together b b.id = c.fk
i looking universal solution both oracle , sql server.
question 2
how know position current row (within result of above query). example, if want implement logic "this no. x of y".
for confused neighbour rows is, mean previous or next row of each row above query. result query might quite different 1 above, idea, can specify position of particular d in whole entity using java don't know how using sql.
if using oracle, lead , lag keywords, allow select info rows before or after.
sql
Comments
Post a Comment