oracle sql query hangs -


alright i'm trying last 2 columns here: each ticket has journal associated can have multiple entries. trying latest entry given ticket number , based on time stamp associated entry, create query shows how time has elapsed since last entry. last column shows elapsed time well, specific type of journal entry. entries query need restricted tickets have owner id correspond 1 of 2 people. in example, people 'aaaa cccc' , 'bbbb dddd'. so, when run query, hangs. also, when remove last 2 columns, still hangs, assume has statement. i'm @ loss here, since i'm quite new sql, there simple i'm missing.

select t.ticket_id,     cct.issue,     t.status,     t.priority,     a.account_name,     o.identifier,     to_char(t.created, 'mm/dd/yyyy hh:mm:ss')    "created",     to_char(sysdate - (select max(ti.timestamp)                          ticket_journal ti                         ti.ticket_id = t.ticket_id), 'hh:mm:ss') "last_entry",     to_char(sysdate - (select max(ti.timestamp)                          ticket_journal ti                         ti.ticket_id = t.ticket_id                               , ( ti.journal_type 'external'                                      or ti.journal_type 'external/wip'                                   )), 'hh:mm:ss')                   "last_ext_entry"    tickets t,     customer_care_tickets cct,     accounts a,     orders o   t.owner in (select cont.contact_id                       contacts cont                      ( cont.first_name 'aaaa'                            or cont.first_name 'bbbb' )                     , ( cont.last_name 'cccc'                          or cont.last_name 'dddd' ))  

looks may have cartesian join here. http://www.orafaq.com/wiki/cartesian_join

i'm not sure how database keys constructed guessed below, may give idea of how need link tables. these ansi joins, not oracle-specific. recommend learn use these types of joins code more portable. hope helps.

for outer joins use full join inner joins use join or inner join. left/right joins use left join or right join.

from tickets t    join customer_care_tickets cct on t.ticket_id = cct.ticket_id    join accounts on cct.account_id = a.account_id    join orders o on o.ticket_id = t.ticket_id  t.owner in (select cont.contact_id                       contacts cont                      ( cont.first_name 'aaaa'                            or cont.first_name 'bbbb' )                     , ( cont.last_name 'cccc'                          or cont.last_name 'dddd' ))  

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -