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

I created a view in MySql. But now my requirement is to create an identifier column in this view, which should grow automatically.

My current view: -

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 the Identifier column to be the first column to be auto-active in nature. How can I do it? Thanks in advance.

+6
source share
4 answers

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

 SELECT @rownum: =@rownum +1 AS rownum, dummy.* FROM (SELECT @rownum:=0) r, dummy; 
+5
source

A database view is a mirror copy of our data from our database. In real life this does not exist. It has the same structure as in the main table.

Therefore, its structure cannot change

+2
source

You can use the "UIID ()" function, which will provide you with a unique (alphanumeric) identification.

Check this out: fooobar.com/questions/425580 / ...

0
source

select @rownum: = @rownum + 1 'autoID', m.mediaThumbnailUrl, q.surveyID from (SELECT @rownum: = 0) r, media m attach question q to m.mediaAutoID = q.backgroundImageID;

-1
source

Source: https://habr.com/ru/post/947628/


All Articles