---
title: "3 Top Rules to Create a View in SQL"
description: "Three SQL rules to create a view. This is almost same in DB2, Oracle and Teradata. Also given ready made best example on how to create view and also to get data from view using SQL Query."
url: https://srinimf.com/2017/12/19/create-view-awesome-sql-query-to-your-project/
date: 2017-12-19
modified: 2026-10-20
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2017/12/view-sql-query.png?fit=517%2C334&ssl=1
categories: ["SQL"]
tags: ["Create view in SQL", "SQL tips and tricks"]
type: post
lang: en
---

# 3 Top Rules to Create a View in SQL

Here are basic rules you need to create [a view](https://srinimf.com/2023/11/02/how-to-create-a-view-in-db2-an-example-sql/). I have shared already what is [read only view and updatable view](https://srinimf.com/2015/11/22/2-types-of-view-updatable-and-read-only-advanced-sql/).

View is a logical table. On top of base table yoy can create it. Here are three rules.

1. No ORDER BY inside the View CREATE
2. All Aggregation needs to have an ALIAS
3. Any Derived columns (such as Math) needs an ALIAS

Here’s Sample SQL to create View

```
CREATE View Department_Salaries AS
 SELECT     Dept_No
            ,SUM(Salary) as SumSal
            ,SUM(Salary) / 12 as MonthSal
 FROM Employee_Table
 GROUP BY 1;
```

The above is the query to create a view. You can read one more example to create a view.

**However, the SQL below is to retrieve data from SQL query**

```
SEL *
 FROM Department_Salaries
 Order By 1 ;
```

```
Dept_No    SumSal    MonthSal
________  ________  __________
     ?    32800.50   2733.38
    10    64300.00   5358.33
   100    48850.00   4070.83
   200    89888.88   7490.74
   300    40200.00   3350.00
   400   145000.00  12083.33
```

Also read how Salesforce is using [AI without SQL](https://techcrunch.com/2017/08/29/salesforce-is-using-ai-to-democratize-sql-so-anyone-can-query-databases-in-natural-language/) for your quick reference.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2017%2F12%2F19%2Fcreate-view-awesome-sql-query-to-your-project%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2017%2F12%2Fview-sql-query.png%3Ffit%3D517%252C334%26ssl%3D1&description=3%20Top%20Rules%20to%20Create%20a%20View%20in%20SQL)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2017/12/19/create-view-awesome-sql-query-to-your-project/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2017/12/19/create-view-awesome-sql-query-to-your-project/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2017/12/19/create-view-awesome-sql-query-to-your-project/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2017/12/19/create-view-awesome-sql-query-to-your-project/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%203%20Top%20Rules%20to%20Create%20a%20View%20in%20SQL&body=https%3A%2F%2Fsrinimf.com%2F2017%2F12%2F19%2Fcreate-view-awesome-sql-query-to-your-project%2F&share=email)
-

### Like this:

Like Loading…
