Creating a View containing one or more SQL Tables

This is just a template to help you define a view between two or more tables. All you have to do here is specify the fields that you need in the view and the criteria to join the tables.
CREATE OR REPLACE VIEW SCHEMA.TABLE_NAME as (                              
    SELECT     TABLE1.field1, TABLE1.field2, TABLE1.field3,               
        TABLE1.field4, TABLE1.field5, TABLE1.field6,    
        TABLE2.field1, TABLE2.field2, TABLE3.field3,      
        TABLE3.field1, TABLE3.field2, TABLE3.field3 
    FROM TABLE1 left outer join TABLE2 on 
        TABLE1.field1 = TABLE2.field1 and 
        TABLE1.field2 = TABLE2.field2 
    left outer join TABLE3 on 
        TABLE1.field1 = TABLE3.field1 and 
        TABLE1.field2 = TABLE3.field2 and
        TABLE1.field3 = TABLE3.field3 
    );

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.