Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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

SQL ORDER BY With WHERE

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

SQL ORDER BY Clause

SELECT *
FROM Customers
ORDER BY first_name;
Comment

PREVIOUS NEXT
Code Example
Sql :: column get from sql table 
Sql :: drop index oracle 
Sql :: mssql disable foreign key constraint 
Sql :: sql server get schema of table 
Sql :: calculate age in sql postgresql 
Sql :: sql remove last 2 digit 
Sql :: mysql show table structure 
Sql :: show constraints mysql 
Sql :: calculate distance between two latitude longitude postgresql 
Sql :: postgres datetime now 
Sql :: CONCAT_WS() concat function in mysql 
Sql :: postgresql dump and restore db 
Sql :: MySQL server is running with the –secure-file-priv 
Sql :: date_part mysql 
Sql :: is not numeric sql 
Sql :: mysql show table fields 
Sql :: mysql case when on date 
Sql :: sql query to list all tables in a database sql server 
Sql :: how to login sql server using cmd 
Sql :: create stored procedure 
Sql :: create table employees oracle 
Sql :: ascending order mysql 
Sql :: mysql where not equal 
Sql :: mysql count number of occurrences in a column 
Sql :: mysql failed to login as root@localhost 
Sql :: update table from another table 
Sql :: sql server alter table add column tinyint 
Sql :: oracle apex charging debug 
Sql :: sql groub by count 
Sql :: get time component of datetime sql 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =