<h2>Example left join in creating a database view</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="task" /><meta name="DC.title" content="Example left join in creating a database view" /><meta name="abstract" content="This example shows the proper settings when using left-joins to add tables to a database view." /><meta name="description" content="This example shows the proper settings when using left-joins to add tables to a database view." /><meta name="DC.relation" scheme="URI" content="../../../use/reporting/task/c_CreatingDatabaseViews.html" /><meta name="DC.relation" scheme="URI" content="../../../build/custom-application/concept/build-applications.html" /><meta name="DC.relation" scheme="URI" content="../../../build/custom-application/concept/planning-applications.html" /><meta name="DC.relation" scheme="URI" content="../../../use/reporting/concept/c_DatabaseViews.html" /><meta name="DC.relation" scheme="URI" content="../../../use/reporting/task/t_AddATableToTheDatabaseView.html" /><meta name="DC.relation" scheme="URI" content="../../../use/reporting/concept/c_SpecifyAFieldToReturn.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2023-08-03" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="example-left-join-db-view" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>Example left join in creating a database view</title></head><body id="example-left-join-db-view"> <div class="breadcrumb"><a class="link" href="../../../use/reporting/task/t_AddATableToTheDatabaseView.html" title="Add a table to the database view">Previous topic</a> | <a class="link" href="../../../use/reporting/concept/c_SpecifyAFieldToReturn.html" title="Specify a field to return">Next topic</a> | <a class="link" href="../../../build/custom-application/concept/build-applications.html" title="Learn how to become an application developer using Now Platform low-code tools. Start with what you know and use a library of reusable components and published applications to modernize your legacy processes.">Building applications</a> > <a class="link" href="../../../build/custom-application/concept/planning-applications.html" title="The application development process starts with planning. Consider how the application will work, who will use it, and how it improves user experience.">Planning your application</a> > <a class="link" href="../../../use/reporting/concept/c_DatabaseViews.html" title="A database view defines table joins for reporting purposes.">Creating database views for reporting</a> > </div> <h1 class="title topictitle1" id="ariaid-title1">Example left join in creating a database view</h1> <div class="body taskbody"><p class="shortdesc">This example shows the proper settings when using left-joins to add tables to a database view.</p> <div class="section prereq p">Role required: admin</div> <div class="section context" id="example-left-join-db-view__context_i2j_tqk_1gb">The following procedure shows how to create a database view that includes a list of Catalog Tasks and their parents. Most of the steps take place on the View Table form.<br /><img class="image" id="example-left-join-db-view__image_ixs_qhl_1gb" src="../image/Dbviews4.png" alt="Creating views with left joins." /><br /> </div> <ol class="ol steps"><li class="li step stepexpand"> <span class="ph cmd">Navigate to <span class="ph menucascade"><span class="ph uicontrol">All</span> > <span class="ph uicontrol">System Definition</span> > <span class="ph uicontrol">Database Views</span></span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Select the view you want to edit.</span> <div class="itemgroup stepresult">The Database View page appears. In the View Tables related list, specify the tables you want in the database view.</div> </li><li class="li step stepexpand"> <span class="ph cmd">In the <span class="ph uicontrol">View Tables</span> related list, select <span class="ph uicontrol">New</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Add a <span class="ph uicontrol">Left join</span> check box to the form by <a class="xref" href="../administer/form-administration/concept/configure-form-layout.dita/configure-form-layout.html" target="_blank" rel="noopener noreferrer">Configuring the form layout</a>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Add the Catalog Task [sc_task] table to the database view by filling in the form with the following data and then select <span class="ph uicontrol">Submit</span>. <span class="ph">Joined tables are ordered left to right from lowest to highest <span class="ph uicontrol">Order</span> values.</span></span> <div class="itemgroup info"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="example-left-join-db-view__table_vqd_tvk_1gb" class="table" frame="border" border="1" rules="all"><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e129">Field</th><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e132">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e129 ">Table</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e132 ">Catalog Task [sc_task]</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e129 ">Variable prefix</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e132 ">cat</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e129 ">Order</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e132 ">100</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e129 ">Where clause</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e132 ">Leave blank</td></tr></tbody></table> </div> </div> <div class="itemgroup stepresult">The Database View page appears with the Catalog Task table in the View Tables table.</div> </li><li class="li step stepexpand"> <span class="ph cmd" id="example-left-join-db-view__cmd_wrl_2wk_1gb">In the <span class="ph uicontrol">View Tables</span> table, select <span class="ph uicontrol">New</span> and add the Requested Item [sc_req_item] table to the database view by filling in the form with the following data and then selecting <span class="ph uicontrol">Submit</span>. <span class="ph">Joined tables are ordered left to right from lowest to highest <span class="ph uicontrol">Order</span> values.</span></span> <div class="itemgroup info"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="example-left-join-db-view__table_rnf_jwk_1gb" class="table" frame="border" border="1" rules="all"><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e217">Field</th><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e220">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e217 ">Table</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e220 ">Requested Item [sc_req_item]</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e217 ">Variable prefix</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e220 ">item</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e217 ">Order</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e220 ">200</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e217 ">Where clause</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e220 ">cat_parent=item_sys_id</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e217 ">Left join check box</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e220 ">True</td></tr></tbody></table> </div> </div> <div class="itemgroup stepresult">The Database View page appears with the Requested Item table in the View Tables table.</div> </li><li class="li step stepexpand"> <span class="ph cmd">In the <span class="ph uicontrol">View Tables</span> table, select <span class="ph uicontrol">New</span> and add the Request [sc_request] table to the database view by filling in the form with the following data and then selecting <span class="ph uicontrol">Submit</span>.</span> <div class="itemgroup info"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="example-left-join-db-view__table_tln_vwk_1gb" class="table" frame="border" border="1" rules="all"><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e308">Field</th><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e311">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e308 ">Table</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e311 ">Request [sc_request]</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e308 ">Variable prefix</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e311 ">req</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e308 ">Order</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e311 ">300</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e308 ">Where clause</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e311 ">cat_parent=req_sys_id</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e308 ">Left join check box</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e311 ">True</td></tr></tbody></table> </div> </div> <div class="itemgroup stepresult">The Database View page appears with the Request table in the View Tables table.</div> </li><li class="li step stepexpand"> <span class="ph cmd">In the <span class="ph uicontrol">View Tables</span> table, select <span class="ph uicontrol">New</span> and add the User [sys_user] table to the database view by filling in the form with the following data and then selecting <span class="ph uicontrol">Submit</span>.</span> <div class="itemgroup info"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="example-left-join-db-view__table_hhk_2xk_1gb" class="table" frame="border" border="1" rules="all"><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e399">Field</th><th class="entry cellrowborder" style="text-align:left;vertical-align:top;" id="d374622e402">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e399 ">Table</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e402 ">User [sys_user]</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e399 ">Variable prefix</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e402 ">user</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e399 ">Order</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e402 ">400</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e399 ">Where clause</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e402 ">cat_opened_by=user_sys_id</td></tr><tr class="row"><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e399 ">Left join check box</td><td class="entry cellrowborder" style="text-align:left;vertical-align:top;" headers="d374622e402 ">False</td></tr></tbody></table> </div> </div> <div class="itemgroup stepresult"> <ul class="ul" id="example-left-join-db-view__ul_jzg_rj1_2gb"><li class="li">The Database View page appears with the User table in the View Tables table.</li><li class="li">If the parent record of Catalog Task is a Requested Item, all the fields in the Request table will be blank.</li><li class="li">If the parent record is a Request, all the fields in Requested Item will be blank.</li><li class="li">Because of the two left joins, the Catalog Task record returns even if the parent is empty or is not a Requested Item or Request.</li><li class="li">Because User is not a left join, there must be a matching user in sys_user for the row’s Opened By field for the Catalog Task row to return.</li></ul> </div> </li><li class="li step stepexpand"><strong>Optional: </strong> <span class="ph cmd">Perform the following steps to experiment and learn more about how left joins impact database views.</span> <div class="itemgroup info">If you make the left join in:<ul class="ul" id="example-left-join-db-view__ul_sks_kk1_2gb"><li class="li">User true, rows that have an empty <span class="ph uicontrol">Created By</span> return.</li><li class="li">Requested Item false, only Catalog Tasks that have a Requested Item as a parent return.</li><li class="li">Request false, only Catalog Tasks that have a Request as a parent return.</li><li class="li">Requested Item and Request false, no rows return because nothing can have a Requested Item and a Request as parents.</li></ul> </div> </li></ol> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../use/reporting/task/c_CreatingDatabaseViews.html" title="Create a database view to join tables. You can then create a report based on the database view.">Database view creation</a></div> <div class="previouslink"><strong>Previous topic:</strong> <a class="link" href="../../../use/reporting/task/t_AddATableToTheDatabaseView.html" title="Specify the table to join to the database view.">Add a table to the database view</a></div> <div class="nextlink"><strong>Next topic:</strong> <a class="link" href="../../../use/reporting/concept/c_SpecifyAFieldToReturn.html" title="Restrict or specify a field that you want returned by the joined table.">Specify a field to return</a></div> </div> </div></body></html></div>