Search
 
SCRIPT & CODE EXAMPLE
 

SQL

order by sql

//this_for_descending_order.. 
 SELECT * FROM TableName ORDER BY columnName DESC;
 // this_for_ascending_order..
SELECT * FROM TableName ORDER BY columnName ASC;
Comment

sql order by where condition

SELECT ProcductCode AS Id, ProductPrice AS Price
FROM Products WITH (NOLOCK)
WHERE ProductCode IN ('efg', 'abc', 'xyz')
ORDER BY (CASE WHEN ProductCode = 'efg' THEN 1
               WHEN ProductCode = 'abc' THEN 2
               WHEN ProductCode = 'xyz' THEN 3
               ELSE 4  -- in case you change the `where`, put them last
          END);
Comment

sort by sql

SELECT * FROM table_name ORDER BY col1 ASC;				-- ASCending is default
SELECT * FROM table_name ORDER BY col1 DESC;			-- DESCending
SELECT * FROM table_name ORDER BY col1 DESC, col2;	 	-- col1 DESC then col2 ASC
Comment

SQL ORDER BY With WHERE

SELECT last_name, age
FROM Customers
WHERE NOT country = 'UK'
ORDER BY last_name DESC;
Comment

sql query order

SQL order of execution defines the
execution order of clauses.

-Select
It starts execution with 
-from  (Choose and join tables to get base data)
after from
-where ( filters base data )
-group by (Aggregates base data)
-having (filters aggregated data)
-select (returns final data)
-order by (sorts the final data)
-limit (limits the returned data to a row count)

Only select and from are mandatory
Comment

sql order by

Used to sort the result data in ascending (default) or descending order
through the use of ASC or DESC keywords.
Example: Returns countries in alphabetical order.
SELECT * FROM countries
ORDER BY name;
Comment

SQL ORDER BY Clause

SELECT *
FROM Customers
ORDER BY first_name;
Comment

order by in sql

ORDER BY: is for sorting result
either in descending or ascending order.
Comment

PREVIOUS NEXT
Code Example
Sql :: identity syntax in sql 
Sql :: oracle gather table statistics 
Sql :: sql server on mac m1 
Sql :: sql insert values into table 
Sql :: postgresql delete all content 
Sql :: php get closest location by latitude longitude 
Sql :: PostgreSQL: To_Number function 
Sql :: declare temp table in sql 
Sql :: sql to linq 
Sql :: SQL SELECT TOP Equivalent in MySQL 
Sql :: datagrip execute procedure 
Sql :: mysql get only the field names in a table 
Sql :: restore backup "text" postgresql command line 
Sql :: joins in sql 
Sql :: mysql last friday of current month 
Sql :: add column postgresql 
Sql :: change database postgres 
Sql :: oracle drop type 
Sql :: sql server datetime vs datetime2 
Sql :: how to create triggers in sql server 
Sql :: sql comments 
Sql :: mysql string split to array 
Sql :: pl sql search saurce code 
Sql :: azure check access to sql database 
Sql :: sql delete duplicate rows but keep one 
Sql :: how to replace null values in sql 
Sql :: show sql property syntax for jpa. 
Sql :: Inserting data into different tables at once in oracle sql 
Sql :: oracle undo usage per session 
Sql :: reindex mssql table 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =