title: SortableGridField causing SQL error
body: <p>After a lot of searching, I found: <a href="https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ManyManyExample.md" rel="nofollow">https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ManyManyExample.md</a> for an example of usage.</p>
  
  <p>However, implementing this code results in:</p>
  
  <p>[User Error] Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') Column 'SortOrder' in field list is ambiguous</p>
  
  <p>I'm using SS3 and have SortableGridField installed (though no messages indicated successful installation upon running dev/build/?flush=all).</p>
  
  <p>With Dev mode off, the CMS does not load ("Server Error"), however with Dev mode enabled, I get the above SQL error. Regardless, it seems to be working properly, I just need to find out why this error is being thrown.</p>
  
  <p>UPDATE</p>
  
  <p>Below is the top part of the stack traces generated on this error (there are 2 [User Error] blue headers on the page):</p>
  
  <pre><code>[User Error] Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') Column 'SortOrder' in field list is ambiguous
  Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') Column 'SortOrder' in field list is ambiguous 
  MySQLDatabase.php:580
  MySQLDatabase-&gt;databaseError(Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') | Column 'SortOrder' in field list is ambiguous,256) 
  MySQLDatabase.php:132
  MySQLDatabase-&gt;query(SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2'),256) 
  DB.php:200
  DB::query(SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2'),256) 
  SQLQuery.php:949
  SQLQuery-&gt;execute() 
  DataQuery.php:372
  DataQuery-&gt;aggregate(MAX("SortOrder")) 
  DataQuery.php:338
  DataQuery-&gt;max(SortOrder) 
  DataList.php:676
  DataList-&gt;max(SortOrder) 
  GridFieldSortableRows.php:148
  GridFieldSortableRows-&gt;fixSortColumn(GridField,ManyManyList) 
  GridFieldSortableRows.php:99
  GridFieldSortableRows-&gt;getManipulatedData(GridField,ManyManyList) 
  GridField.php:215
  GridField-&gt;getManipulatedList() 
  GridField.php:255
  GridField-&gt;FieldHolder() 
  ...
  
  [User Error] Couldn't run query: SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0) Column 'SortOrder' in where clause is ambiguous
  
  Couldn't run query: SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0) Column 'SortOrder' in where clause is ambiguous 
  MySQLDatabase.php:580
  MySQLDatabase-&gt;databaseError(Couldn't run query: SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0) | Column 'SortOrder' in where clause is ambiguous,256) 
  MySQLDatabase.php:132
  MySQLDatabase-&gt;query(SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0),256) 
  DB.php:200
  DB::query(SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0),256) 
  SQLQuery.php:949
  SQLQuery-&gt;execute() 
  SQLQuery.php:1054
  SQLQuery-&gt;count(DISTINCT "Sidebar"."ID") 
  DataQuery.php:329
  DataQuery-&gt;count() 
  DataList.php:666
  DataList-&gt;count() 
  GridFieldSortableRows.php:150
  GridFieldSortableRows-&gt;fixSortColumn(GridField,ManyManyList) 
  GridFieldSortableRows.php:99
  GridFieldSortableRows-&gt;getManipulatedData(GridField,ManyManyList) 
  GridField.php:215
  GridField-&gt;getManipulatedList() 
  GridField.php:255
  GridField-&gt;FieldHolder() 
  ViewableData.php:366
  ViewableData-&gt;obj(FieldHolder,,,1) 
  ...
  </code></pre>