Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql order by on condition

 SELECT * 
    FROM my_table 
    WHERE 1  
    ORDER BY 
      CASE price WHEN 0 THEN 1
       ELSE -1
      END ASC, price asc, id asc
Comment

condition in orderby mysql

SELECT orders.status, orders.created_at
FROM `orders`
ORDER BY
  status='new' DESC,
  status='processing' DESC,
  CASE WHEN status IN ('new', 'processing') THEN created_at END ASC,
  CASE WHEN status NOT IN ('new', 'processing') THEN created_at END DESC
Comment

PREVIOUS NEXT
Code Example
Sql :: sql max min 
Sql :: open postgresql.conf in centos 
Sql :: timestamp datatype in sql 
Sql :: select only unique values from and to current table 
Sql :: 2 max value in sql 
Sql :: sql comments 
Sql :: postgres stored procedure 
Sql :: minus equivalent in my sql 
Sql :: sqlite clear console 
Sql :: changing column names in sql query results 
Sql :: SQL Server Splitting a string column into multiple rows, while repeating ID column 
Sql :: sql use with to get value counts and percentages 
Sql :: how to check last index rebuild sql server 
Sql :: sql select rows with simlar names 
Sql :: c# sql conennection string 
Sql :: postgres insert into table 
Sql :: postgres show table schema 
Sql :: select all from table left join 
Sql :: Host ' is not allowed to connect to this MySQL server 
Sql :: delete row mysql 
Sql :: greater than or equal to symbol in postgres 
Sql :: postgresql like 
Sql :: FIND ABOVE AVERAGE SALARY EARNER IN SQL 
Sql :: sql create database statement 
Sql :: learn sql 
Sql :: show broken table mysql 
Sql :: Ms Sql set us timezone 
Sql :: initcap in mysql 
Sql :: what are the data types in sql 
Sql :: hyphen error in database mysql 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =