sql - Creating a view for 3 tables with a little complex relationships -
so have 3 tables, "ruta", "track_ruta", "punto_ruta" ruta has relationship of 1 many track_ruta , relationship of 1 many punto_ruta. track_ruta has relationship of 1 many punto_ruta. ruta means route in spanish way. long story short route has tracks , tracks have points. there can points without tracks belong route. why way is. need retrieve , searches according dates on points , need points of route. had sql sentence
select distinct p.* puntoruta p, ruta r, trackruta t ((r.codigo=routeid , t.ruta.codigo=r.codigo , p.trackruta.codigo=t.codigo) or p.ruta=routeid)
routeid replacing id on code
this worked. dont using distinct know costly , worked while. until user had million points on route , takes ever search when using limits. have not had handle complex db relations in ages rusty.
i fuzzy on how transform view. using joins this
select * punto_ruta p join track_ruta t on p.id_track_ruta=t.id_track_ruta join ruta r on r.id_ruta=t.id_ruta right outer join ruta r1 on r1.id_ruta=p.id_ruta
i tried full outer join in both cases adding routes @ end. no able add points belong route , not track.
should combine 2 queries? adding this
select p.* punto_ruta p join ruta r on r.id_ruta=p.id_ruta
to query before?
let independed points have null
in track_id
r(id, ...) t(id, r_id, ...) p(id, r_id, t_id, ...) select p.* p p.r_id = routeid , p.t_id null union select p.* t left join p on t.id = p.t_id t.r_id = routeid
Comments
Post a Comment