Answers.Body: <p>So this was me being a bit of a numpty here. I was calling the field the wrong way. Doing the following obeys the sort order from the field:</p>
  
  <pre><code>{% for entry in block.hostingPackage %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T15:50:18.350Z
Answers.LastActivityDate: 2018-08-29T15:50:18.350Z
Answers.UserDisplayName: richardpixel
Body: <p>I'm getting the following SQL error when trying to simply order related entries in a Matrix block. Anyway around this?</p>
  
  <blockquote>
    <p>CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'sortOrder' in order clause is ambiguous. The SQL statement executed was: SELECT <code>elements</code>.<code>id</code>, <code>elements</code>.<code>type</code>, <code>elements</code>.<code>enabled</code>, <code>elements</code>.<code>archived</code>, <code>elements</code>.<code>dateCreated</code>, <code>elements</code>.<code>dateUpdated</code>, ...</p>
  </blockquote>
  
  <p>This is what's throwing the error:</p>
  
  <pre><code>{% set package = craft.entries({
  relatedTo: block,
  order: 'sortOrder'}) %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-28T16:25:31.023Z
Comments.Text: Are you working in Craft 2 or Craft 3?
Comments.UserDisplayName: a-am
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-28T16:40:18.413Z
Comments.Text: I'm using Craft 2. Updated the question.
Comments.UserDisplayName: richardpixel
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-28T17:39:29.773Z
Comments.Text: I don't believe you need the `order: 'sortOrder'` it does that by default when you access related entries.  Here is another post that may be of help. https://craftcms.stackexchange.com/questions/4654/custom-order-related-entries/4657#4657
Comments.UserDisplayName: a-am
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-29T08:51:37.443Z
Comments.Text: Thanks @aran but no, it's not obeying the sortOrder. I only seem to come across this issue on a related entry within a Matrix field block.
Comments.UserDisplayName: richardpixel
Tags: <matrix><relations><ordering><relatedto><sorting>
Title: SQL error when trying to use sortOrder on Matrix related block (Craft 2)
ThreadText: # SQL error when trying to use sortOrder on Matrix related block (Craft 2)
  
  (Asked by: username_0 on 2018-08-28)
  
  I'm getting the following SQL error when trying to simply order related entries in a Matrix block. Anyway around this?
  
  > CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'sortOrder' in order clause is ambiguous. The SQL statement executed was: SELECT `elements`.`id`, `elements`.`type`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, ...
  
  This is what's throwing the error:
  
  ```
  {% set package = craft.entries({
  relatedTo: block,
  order: 'sortOrder'}) %}
  
  ```
  
  **Tags:** matrix, relations, ordering, relatedto, sorting
  
  > **Comments:**
  > **username_1**: Are you working in Craft 2 or Craft 3?  
  > **username_0**: I'm using Craft 2. Updated the question.  
  > **username_1**: I don't believe you need the `order: 'sortOrder'` it does that by default when you access related entries.  Here is another post that may be of help. https://craftcms.stackexchange.com/questions/4654/custom-order-related-entries/4657#4657  
  > **username_0**: Thanks @aran but no, it's not obeying the sortOrder. I only seem to come across this issue on a related entry within a Matrix field block.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-08-29. Score: 1
  
  So this was me being a bit of a numpty here. I was calling the field the wrong way. Doing the following obeys the sort order from the field:
  
  ```
  {% for entry in block.hostingPackage %}
  
  ```
  
  
  ---
  
  