top of page

SQL Views

  • Views are the virtual tables created from some queries and logic.

  • It is not real table, it is just the reflection of the real table.​

Syntax 

CREATE OR REPLACE VIEW view_name as
       (query);
EXAMPLE

CREATE OR REPLACE VIEW v_avg_salary as
         (select monthname(e.hire_date) as Hire_Month ,
          round(avg(s.salary)) as Salary
          from employees e
          join salaries s on e.emp_no = s.emp_no
          group by monthname(e.hire_date)
           order by avg(s.salary) desc); 
  • Views can be run in a similar manner we run a table but we should always remember it is just the virtual table not a real table.

  • Any changes made in a real table will result in a view.

  • Main Benefit of view it saves lot of time and coding. We don't need to write the code from scratch every time, we can just run the view to get the desired output.

bottom of page