Rajeev Kumar
Is it possible to sort a column name using a column name alias?

Is it possible to sort a column name using a column name alias?

By Rajeev Kumar in SQL Server on Jan 03 2023
  • Digambar Bhandare
    Jan, 2023 28

    Not possible it gets error

    • 1
  • Rajeev Kumar
    Jul, 2023 7

    Yes ,it is possible
    select top 5 ArticleId as id from tblarticlemaster order by id desc
    select top 5 ArticleId as id from
    tblarticlemaster order by 1 desc
    This is the result of above query—
    id
    4517
    4516
    4515
    4514
    4513

    • 0
  • Rajeev Kumar
    Jul, 2023 7

    Yes ,it is possible
    select top 5 ArticleId as id from tblarticlemaster order by id desc
    select top 5 ArticleId as id from
    tblarticlemaster order by 1 desc
    This is the result of above query—
    id
    4517
    4516
    4515
    4514
    4513

    • 0
  • Tuhin Paul
    Apr, 2023 15

    It is possible to sort a column using its alias in SQL Server. You can use the alias in the ORDER BY clause to specify the column to sort by.

    1. SELECT column1 AS alias1, column2 AS alias2
    2. FROM table_name
    3. ORDER BY alias1;

    Here we have two columns column1 and column2 from the table table_name. We have also given them aliases alias1 and alias2, respectively. We are then using the alias alias1 in the ORDER BY clause to sort the result set by the values in column1. When using an alias in the ORDER BY clause, you should use the same alias as the one you defined in the SELECT clause. If you use the original column name instead of the alias, the sorting will be done based on the original column name.

    • 0
  • Munib Butt
    Jan, 2023 12

    Yes

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS