SQL creating view with JOIN
View with JOIN
In this page, we are going to discuss, how two or more tables can be involved and join themselves to make a view in CREATE VIEW statement.
Example:
Sample table: orders
Sample table: customer
Sample table: agents
To create a view 'ordersview' by three tables 'orders', 'customer' and ' agents' with following conditions -
1. 'a' and 'b' and 'c' are the aliases of 'orders' and 'customer' and 'agents' table,
2. 'cust_code' of 'orders' and 'customer' table must be same,
3. 'agent_code' of 'orders' and 'agents' table must be same,
the following SQL statement can be used:
CREATE VIEW ordersview
AS SELECT ord_num, ord_amount, a.agent_code,
agent_name, cust_name
FROM orders a, customer b, agents c
WHERE a.cust_code=b.cust_code
AND a.agent_code=c.agent_code;
Output:

To execute query on this view
SELECT * FROM ordersview;
Check out our 1000+ SQL Exercises with solution and explanation to improve your skills.
Previous: Create view with aggregate functions count(), sum() and avg()
Next: Update View
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join