- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 09:41 PM
Hello everyone,
I'm new to database view.
I have two tables
Table1 extends task
Table1 has 2 fields
field1 - String (Example. Phone)
field2 - Reference to table2 (Example. Samsung)
Table2 does not extend any table
Table2 has 2 fields
field1 - String(this is the reference record used in table1) (Example. Samsung)
field2 - String(Example. note 15)
Is there any way where I could see field1, field2 of table1 and field1 field2 of table2. (Phone Samsung Samsung Note 15) using database view?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 09:50 PM
In ur case when u create database view based upon prefix wht u provide it should look something like below
You should write this in where clause of table 2
Lets say prefix u have kept is table1 & table2
Then ur where clause would look like
table1.field2=table2.sys_id
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 09:58 PM
Hi @Tharun_M ,
You can take below link as reference on incident and problem table
https://www.servicenow.com/community/developer-forum/database-view-select-data-from-2-tables/m-p/135...
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 09:58 PM
Hi,
Create the database view with view tables - Table1 and Table 2 and
add a left join with a where clause as - WHERE Table1<var prefix>.field2 = Table2<var prefix>.field1
Try once
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 10:02 PM
@Tharun_M Below blog will definitely help you to understand the database view. Also see the video linked in it.
For your case, it is possible to create database view and get all fields of table1 & table2 in single view. You can refer below OOB database view for reference.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 10:54 PM
Hi @Tharun_M
According to your description, you state that table1 field2 and table2 field 1 is both string fields but also reference fields - what is correct? If it is reference fields, then you can just dot-walk without the need of a database view. Note that your table1.field2 and table2.field1 is Samsung. I would assume that there are several samsung models, so not the best option to do a database view upon. To create a Database view, you should have a 1-1 or a 1-m relationship between the two tables.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/