View

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
tostay2003
Participant
Posts: 97
Joined: Tue Feb 21, 2006 6:45 am

View

Post by tostay2003 »

Can a view have more than one table in it. If at all yes. then how do i read from different tables. Like say I have

Code: Select all

VIEW  - Table1     -   ID1
                   -   ID2
                   -   Value1
      - Table2     -   ID2
                   -  Value2

Extract Requirement

ID1
ID2
Value1
Value2


do i need to say

Code: Select all

select  ID1,
         ID2,
         Value1,
         Value2 
from  VIEW 
where Table1.ID2=Table2.ID2
Am I in the right direction??
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

A view is just a logical construct that treats a result set like a table, and yes it can include more than one base table. It's already 'pre-joined', it's nothing you need to monkey with... all you may need to add are additional filters in the where clause you use to access it.

If the joins are inappropriate for what you need to do, get a new view. :wink:

If you are asking if you can join views to other tables, yes you can do that too - but it tends to be pretty darn inefficient.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If the view is defined with WHERE Table1.ID = Table2.ID then you don't need that particular WHERE clause in a SELECT from the view - indeed, it would generate an error.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

The query to create the view would be

Code: Select all

Create View Veiw1 as Select a.ID1 As ID1, a.ID2, As ID2 a.Value1 As Value1, b.Value2 As Value2 from Table1 a, Table2 b where a.ID2 = b.ID2
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Post Reply