![]() ![]() ![]() This query produces the same result as the complex one with the joins above. INNER JOIN country USING (country_id) Code language: PHP ( php )įrom now on, whenever you need to get complete customer data, you just query it from the view by executing the following simple SELECT statement: SELECTĬustomer_master Code language: SQL (Structured Query Language) ( sql ) However, you can create a view named customer_master as follows: CREATE VIEW customer_master AS The result of the query is as shown in the screenshot below: INNER JOIN country USING (country_id) Code language: SQL (Structured Query Language) ( sql ) If you want to get complete customers data, you normally construct a join statement as follows: SELECT cu.customer_id AS id,Ĭu.first_name || ' ' || cu.last_name AS name,ĬASE WHEN cu.activebool THEN 'active' ELSE '' END AS notes, PostgreSQL CREATE VIEW exampleįor example, in our sample database, we have four tables: ![]() A query can be a simple SELECT statement or a complex SELECT statement with joins. The simplest syntax of the CREATE VIEW statement is as follows: CREATE VIEW view_name AS query Code language: SQL (Structured Query Language) ( sql )įirst, you specify the name of the view after the CREATE VIEW clause, then you put a query after the AS keyword. To create a view, we use CREATE VIEW statement. A view provides a consistent layer even the columns of the underlying table change.Like a table, you can grant permission to users through a view that contains specific data that the users are authorized to see.A view helps simplify the complexity of a query because you can query a view, which is based on a complex query, using a simple SELECT statement.A view can be very useful in some cases such as: ![]()
0 Comments
Leave a Reply. |