Database view with a three table join

ayman_h
Kilo Sage
Kilo Sage

Hi,

I am trying to create a database view that will give me all the SLAs linked to Incidents, where the Incident doesn't have an Incident Task related to it. 

 

I am struggling trying to do this using a join.

 

Does anyone have an idea how I can do this?

 

Thanks,

Ayman

 

 

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

I had some time finally to look into the problem and below you'll find how I solved this in my PDI.

This is how the definition of the database view looks like:
dbv.png

The where clause for table task_sla is:

not exists (select 1 from `task` inct where `inct`.`sys_class_name` = 'incident_task' and `inct`.`a_ref_1` = `inc`.`sys_id`)

The where clause for table incident is:

inc.sys_id = tsla.task

The key part of the solution is finding the storage alias for field incident on table incident_task - a_ref_1 in the where clause for table task_sla.

For this one should open table Storage Column Aliases (sys_storage_alias) and filter it down to where Table (table_name) is incident_task and Element name (element_name) is incident:

dbv2.png

 Whatever is in column Storage alias (storage_alias) - a_ref_1 in my PDI - should be used.

 

(B.t.w. all the back-ticks are not really necessary, not exists (select 1 from task inct where inct.sys_class_name = 'incident_task' and inct.a_ref_1 = inc.sys_id) works just fine).

View solution in original post

10 REPLIES 10

Yeah, it should be the same but it's better to check 🙂

Glad it works, and thanks for marking the correct answer.