Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgres update with if condition query

update t1
        set t1.current_location =   
        CASE  
			WHEN SUBQUERY.status = 0 THEN 'Deployed' 
			WHEN SUBQUERY.status = 1 THEN 'Retrieved' 
			WHEN SUBQUERY.status = 2 THEN 'Lost' 
            ELSE t1.current_location
		END 
from (
    select t3.serial_number, t2.status
    from t2 inner join t3
        on t2.some_id = t3.some_id
    ) as SUBQUERY

where SUBQUERY.serial_number = t1.serial_number;
Comment

postgres update with if condition query

update t1 
  set current_location = 
    case t2.status
        when 0 then 'Deployed'
        when 1 then 'Retrieved'
        when 2 then 'Lost'
    end
from t2 inner join t3
   on t2.some_id = t3.some_id
where t3.serial_number = t1.serial_number;
Comment

update statement postgres

UPDATE table_name
SET column1 = value1,
    column2 = value2,
    ...
WHERE condition
RETURNING * | output_expression AS output_name;
Code language: SQL (Structured Query Language) (sql)
Comment

PREVIOUS NEXT
Code Example
Sql :: delete db postgres 
Sql :: postgres like case insensitive 
Sql :: add time to date sql 
Sql :: mysql order by multiple columns 
Sql :: select distinct postgres 
Sql :: mysql remove records 
Sql :: alter table mysql 
Sql :: mssql datetime to date 
Sql :: create scalar function in sql server 
Sql :: SQL: get date difference in minutes 
Sql :: postgresql import data from csv 
Sql :: drop CHECK constraint sql 
Sql :: average salary in sql 
Sql :: oracle all_dependencies 
Sql :: create table as select * from table mssql 
Sql :: postgresql full text search 
Sql :: Query to remove duplicate rows from a table 
Sql :: minus in sql 
Sql :: sql left 
Sql :: laravel eloquent get generated sql 
Sql :: sql online compiler 
Sql :: sql delete duplicate 
Sql :: oracle create table primary key 
Sql :: sql primary key syntax 
Sql :: add clumn to table postgres 
Sql :: delete * from where id = 1; 
Sql :: docker add mysql to image 
Sql :: run docker container with database as rds metabase 
Sql :: how to get nth number in sql 
Sql :: sql script to remove default from column 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =