+ 1
Can anyone Explain about Views in SQL..?
I want to learn about Views plz help me.
7 ответов
+ 7
Just imagine that you own an E-commerce website and you always try to keep track of the top 10 products with highest ratings by customers.
Now what you can do is create a separate table to store that information but it would be difficult to update the table every time a new product gets more rating.
So what you can do is-
create view Top_10 as select * from Product
Order by rating desc
Limit 10;
Here Product is the table name that already exist and rating is one of the column.
Every time a new product gets the best rating, it will be automatically updated in the Top_10 view which is a temporary table.
Hope this helps.
+ 11
CREATE VIEW List AS
SELECT acc_id, status
FROM users;
SELECT * FROM List
it is a correct answer just try it (thank you)
+ 3
Hi,
Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real table in the database. We can create a view by selecting fields from one or more tables present in the database. A View can either have all the rows of a table or specific rows based on certain condition.
Creating Views
Database views are created using the CREATE VIEW statement. Views can be created from a single table, multiple tables or another view.
To create a view, a user must have the appropriate system privilege according to the specific implementation.
The basic CREATE VIEW syntax is as follows −
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE [condition];
You can include multiple tables in your SELECT statement in a similar way as you use them in a normal SQL SELECT query.
Example
Consider the CUSTOMERS table having the following records −
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Following is an example to create a view from the CUSTOMERS table. This view would be used to have customer name and age from the CUSTOMERS table.
SQL > CREATE VIEW CUSTOMERS_VIEW AS
SELECT name, age
FROM CUSTOMERS;
Now, you can query CUSTOMERS_VIEW in a similar way as you query an actual table. Following is an example for the same.
SQL > SELECT * FROM CUSTOMERS_VIEW;
This would produce the following result.
+----------+-----+
| name | age |
+----------+-----+
| Ramesh | 32 |
| Khilan | 25 |
| kaushik | 23 |
| Chaitali | 25 |
| Hardik | 27 |
| Komal | 22 |
+ 2
You may find answer in https://www.w3schools.com/sql/sql_view.asp
+ 1
Uğur Göktaş No, you can use CREATE VIEW without WHERE clause.
0
do we need to put "WHERE" condition everytime if we use CREATE VIEW ?
"You manage a database of social network users.
Here is the users table with details:contentImage
Write a query to create a view to show only 'acc_id' and 'status' columns and then show that view. "
do you guys have any answer for above quesyions ?