Domanda

I need to do an update query where I'm setting a value based on results from a count query. If the count returns no results, I want to set the status to 1, otherwise i want to set the status to 2.

Here's my attempt which doesn't work:

UPDATE TABLE_1 SET status = ((select count(1) from TABLE_2) > 0 ? 1 : 2)

Also, I'm doing this within a mybatis xml file, so if there is some magic I can do in mybatis that would work too.

È stato utile?

Soluzione

Hope DECODE Helps you! But all the rows in Status updated with same value.. You want it that way ?

UPDATE TABLE_1 SET status = (select DECODE(count(1),0,2,1) from TABLE_2);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top