How to sort view using already sorted array in hook_views_query_alter I have the following code to alter a view and filter IN only specific nodes

function MYMODULE_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if($view-&gt;id() == 'myview'){
    foreach ($query-&gt;where as &amp;$condition_group) {
      foreach ($condition_group['conditions'] as &amp;$condition) {
        if ($condition['field'] == "node_field_data.nid") {
          $condition = array(
            'field' =&gt; "node_field_data.nid",
            'value' =&gt; [2,4,6,1,3,5],
            'operator' =&gt; 'in',
          );
          break;
        }
      }
    } 
    //this does not work    
    //$query-&gt;addOrderBy('node_field_data','nid', 'ASC', '', [2,4,6,1,3,5]);    
  }
}


and I want to sort them with this specific order [2,4,6,1,3,5]

I tried not putting any sorting field but the view sorts the nodes by created date.  How can I tell the view to sort them in this manner ?

I think I need to use ORDER BY FIELD('node_field_data'.'nid','2','4','6','1','3','5') in sql but I don't know how its done in drupal

I have seen this answer but don't know how it applies to my case 

any help would be appreciated
OK I figured it out 

$query-&gt;addOrderBy(NULL, 'FIELD(node_field_data.nid,2,4,6,1,3,5)', 'ASC', 'order_field');