Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create auto increment id column in mysql view?

Tags:

mysql

I have created a view in MySql. But now my requirement is to create an Id column in that view which should be auto increment.

My current view is:-

CREATE VIEW pending_assign_report_view AS
  select cg.group_name,c.client_name, wt.work_type,p.Minor_worktype, ay.year,aev.emp_name,ep.Date_assigned_on
from employee_project ep,active_employee_view aev, project p, client_group cg, client c,work_type wt,assessment_year ay
where ep.task_status_id=1 and ep.username=aev.username and ep.project_id=p.project_id and p.Year_id=ay.Year_id
and p.Client_group_id=cg.client_group_id and p.Client_id=c.Client_id and p.Work_type_id=wt.Work_type_id
order by cg.group_name,c.client_name, aev.emp_name;

Now I want Id column as first column which should be auto_increment in nature. How should I do this? Thanks in advance.

like image 406
Yogesh Patil Avatar asked Jun 19 '13 08:06

Yogesh Patil


1 Answers

You can simulate it with something like this in your SELECT:

SELECT @rownum:=@rownum+1 AS rownum, dummy.*
FROM (SELECT @rownum:=0) r, dummy;
like image 77
Alberto Segura Avatar answered Sep 30 '22 15:09

Alberto Segura