Creating a MySQL view with an auto-incrementing id column
Posted
by hmemcpy
on Stack Overflow
See other posts from Stack Overflow
or by hmemcpy
Published on 2010-05-11T07:22:08Z
Indexed on
2010/05/13
6:34 UTC
Read the original article
Hit count: 238
I have a MySQL database from which a view is created. Is is possible to add an auto-incrementing id for each row in the view?
I tried
CREATE ALGORITHM=UNDEFINED DEFINER=`database_name`@`%` SQL SECURITY DEFINER VIEW `MyView` AS
set @i = 0;
select @i:=@i+1 as `id`
...
but that doesn't work in a View.
Sorry, my SQL is weak, any help is appreciated.
© Stack Overflow or respective owner