A number in the ORDER BY



  • In the ORDER BY clause, what impact does '5' have on the whole query output? I thought ORDER BY could only work in relations with DESC or ASC.

    SELECT
    employee_id,
    first_name,
    last_name,
    hire_date,
    salary
    FROM
    employees
    WHERE
    (salary * 1.5) < 15000
    ORDER BY
    hire_date, 5;
    



  • A number 'n' in the ORDER BY clause refers to the nth field in your SELECT clause.

    In your example, number 5 refers to the salary column in the SELECT. It will therefore order by hire_date first, then on salary second.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2