<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Generate column with unique ID in MySQL view</title><link>https://community.appian.com/discussions/f/general/10068/generate-column-with-unique-id-in-mysql-view</link><description>I&amp;#39;ve often found the need to create views which do not have a single-column primary key, but we must have this primary key column in order to publish a data store which connects to such a view. I suspect that other practitioners have encountered the same</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/58013?ContentTypeID=1</link><pubDate>Mon, 16 Jul 2018 17:42:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:948284f2-2578-4977-bb4f-e9f0ae84c234</guid><dc:creator>Ravi Roshan</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I have tried all above suggestions, however i am getting the error as attached.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="/cfs-file/__key/communityserver-discussions-components-files/11/0537.Capture.PNG"&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/0537.Capture.PNG" alt=" " /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44519?ContentTypeID=1</link><pubDate>Wed, 29 Mar 2017 09:33:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2465d0c6-a1a0-48ba-88cf-5a013e84791f</guid><dc:creator>aloks0189</dc:creator><description>@johns222 @christineh thanks for your valuable inputs, yes the solution mention by @Christineh even worked for me earlier also up-to much extent (apart from some odd cases), however that should work, so if i get such requirement in future, then i will try to implement both of yours suggestions once again&lt;br /&gt;&lt;br /&gt;Thanks.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44507?ContentTypeID=1</link><pubDate>Wed, 29 Mar 2017 01:37:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d64fd718-ee37-4860-a368-e3f9dd95f7d9</guid><dc:creator>John Stretton</dc:creator><description>@aloks Yes, the approach I described is currently working for me. Make sure that your func_inc_var_session() function includes the null check. Christine&amp;#39;s approach would probably work better in many cases, and I might try that next time I have this issue.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44482?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 16:22:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:53fca58a-dde6-4ca4-8937-558a0a5cdff8</guid><dc:creator>ChristineLHutchison</dc:creator><description>Interesting. If you were getting duplicates, I would think that you either did not separate; cause 1:11 is diff from 11:1; use the pk from every table in the joins, or have a unique field from each table. I would look into those. Thanks&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44481?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 16:19:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4c8e08fe-dfff-47d1-872e-2cf40ad009e1</guid><dc:creator>aloks0189</dc:creator><description>@christineh i tried that, initially it was working properly because of having unique PKs combination, but after having huge number of rows getting return from View, i got the duplicate PK again (which was rare, but got that) and again i came back into the same situation where i was earlier. So i tried the solution mention by @Johns but while creating the view it was giving Syntax error but while executing the same in Normal Query was working fine and returning sequence number for each row.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44480?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 16:01:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7f7924c7-e35a-40bc-849f-5152048c342e</guid><dc:creator>ChristineLHutchison</dc:creator><description>The other solution is to concatenate the PKs from all the tables you are selecting together with a : or - or whatever as viewID to make a unique field. Example: 1:2:2:76&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44471?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 08:11:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:286e7607-9374-4327-a8d6-188f384bfa09</guid><dc:creator>aloks0189</dc:creator><description>@johns222 few days ago i too had the same requirement, where my view was joining 6 tables and was returning duplicates for each columns value, so if i treat any one of the column as primary key while mapping it with cdt, and if i query this CDT and use the response in a GridField, then it used to give error because the Primary key value needs to be unique, so i was having the same requirement where a auto sequence has to generate for each row, when i used this query snippet(suggested in Stackoverflow)  in a Normal SQL Query, it was working fine but when i used the same in View, it was giving error. &lt;br /&gt;&lt;br /&gt;@Johns is this solution working for you? if yes, please let me know the steps (or the query for a single column in that view which will hold the autosequence) which you have followed to enable autosequence in view for each row&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44461?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 01:56:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:16def6f4-f6f7-48e1-9186-bb4ba838307d</guid><dc:creator>John Stretton</dc:creator><description>...a data store that connects to the view. Credit for this solution goes to the users who posted on this stackoverflow entry: &lt;a href="http://stackoverflow.com/questions/15891993/create-a-view-with-column-num-rows-mysql"&gt;stackoverflow.com/.../create-a-view-with-column-num-rows-mysql&lt;/a&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Generate column with unique ID in MySQL view</title><link>https://community.appian.com/thread/44460?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 01:56:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4c31a15d-ae2e-4957-a04a-5da4e6a4f8aa</guid><dc:creator>John Stretton</dc:creator><description>...ate a view using this method, you&amp;#39;ll get an error message telling you that variables are not allowed in view definitions. To get around this restriction, we can create a function that initializes a session variable and increments it each time the function is called. If you’re using the MySQL database included with cloud installations of Appian, this query will create the function for you:&lt;br /&gt;&lt;br /&gt;CREATE DEFINER=`appian`@`%` FUNCTION `func_inc_var_session`() RETURNS INT(11) COMMENT &amp;#39;Used to generate unique row IDs in views&amp;#39; NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER begin SET @var := IFNULL(@var,0) + 1; return @var; end&lt;br /&gt;&lt;br /&gt;If you’re on your own MySQL instance, you may need to replace `appian`@`%` with `root`@`localhost`.&lt;br /&gt;&lt;br /&gt;Then, you can create a view definition as follows:&lt;br /&gt;&lt;br /&gt;SELECT func_inc_var_session() AS id, [other column names]&lt;br /&gt;FROM your_tables&lt;br /&gt;&lt;br /&gt;The id column in thsi view will contain a unique ID that Appian can treat as a primary key, and this will allow you to publish ...&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>