sql - Get hierarchy only for updated records -


i have couple of tables resource data

resource ---------- rid |  rname | updatedstamp r1    res1      01-jul-2015 r2    res2      01-jul-2015 r3    res3      01-jul-2015 r4    res4      01-jul-2015 r5    res5      01-jul-2015 r15   res15      01-aug-2015  resourcetree ---------- parid | rid  | updatedstamp --------------------------- null  r1       01-jul-2015 r1    r2       01-aug-2015 r2    r3       01-jul-2015 r3    r4       01-jul-2015   r4    r5       01-jul-2015 r14   r15      01-jul-2015 

i need select query fetch records updated on or after '01-aug-2015'. also, need fetch details of child resources of parent updated on '01-aug-2015'

so in case, need fetch records resource table updated on 01-aug-2015. in case r15. additionally, should fetch details resource_tree table update has happened on or post 01-aug-2015 . in case r2 r3 r4 r5.

results

parid rid rname r14   r15 res15 r1    r2  res2 r2    r3  res3 r3    r4  res4 r4    r5  res5     

query tried far

select rt.parid,r.id,r.rname resources r, resourcetree rt r.rid = rt.rid   , (r.updatedstamp >= '01-aug-2015' or rt.updatedstamp  >= '01-aug-2015') start rt.parid ='r1'  ,  connect prior rt.rid=rt.parid  

this may not elegant solution;

with temp_tbl_1 (    -- "rid" updatedstamp >= '01-aug-2015' both tables   select rid   resourcetree   updatedstamp >= '01-aug-2015'   union   select rid   resource   updatedstamp >= '01-aug-2015' ), temp_tbl_2 (     select parid, rid     resourcetree     start rid in (select distinct rid temp_tbl_1)     connect prior rid = parid     ) select t.parid, t.rid, r.rname  temp_tbl_2 t join resource r on r.rid = t.rid 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -