Home > Software design >  Sql query print one record overwrite if both action are present overwrite and insert
Sql query print one record overwrite if both action are present overwrite and insert

Time:05-19

enter image description hereOutput gives overwrite when action is insert and overwrite both, When only one row (insert/overwrite) is present it should just give that one row

CodePudding user response:

http://sqlfiddle.com/#!9/89c941/3

create table data(id int, action varchar(50));

insert into data(id, action) values(1,'Insert'),(2,'Overwrite'),(3,'Insert Overwrite'),(4,'Overwrite Insert')

select id, 
  action, 
  case when action like '%Overwrite%' 
    then 'Overwrite' 
    else action 
  end as Output
from data

CodePudding user response:

CREATE TABLE userData(_id INT, name VARCHAR(50));

INSERT INTO data(id, name) VALUES(1,'abc'),(2,'xyz')

SELECT _id, case WHEN name LIKE '%xyz%' THEN 'xyz' ELSE name end AS Output FROM userData;

You can use Case insted of switch case.

  • Related