ORDER BY Query in SQL
SELECT ALL ROWS FROM A TABLE BY SQL ORDER BY QUERY: If we need to select all the rows from a table in order either ascending (default) or descending then we may use following query.
SELECT columns FROM table order by column1 ASC, column2 DESC;
To SELECT all rows from customers table with all the Cust_Operators in order i.e. rows with same value for column Cust_Operator together in the final resultset ; use below query:
SELECT Cust_Id, Cust_Name,Cust_City, Cust_Operator FROM customers ORDER by Cust_Operator DESC;
Hence, ORDER BY clause sort the output on the basis of column specified in the clause.
In Teradata, you can also write the above query as :
SELECT Cust_Id, Cust_Name,Cust_City, Cust_Operator FROM customers ORDER by 4 DESC;
Both the queries will result in same output.
To view the original result set click here