GN Code
GN Code

Reputation: 11

How to I set a value if two columns have specific values?

As title say, I need to know how to create a SQL file that will write 1 in every Column B if Column A is 4 and Column B is 2

As a start to make the code, I wrote:

CASE 
    WHEN column_a = '4' 
    WHEN column_b = '2'
        THEN SET column_b = 1
        ELSE
FROM table

I am new to SQL so I apologize if I sound a bit new.

Upvotes: 1

Views: 55

Answers (2)

Silencer310
Silencer310

Reputation: 1090

Try this:

UPDATE table SET ColumnB = 1 where Column B = 2 AND ColumnA = 4;

Upvotes: 0

nos
nos

Reputation: 229058

Your description is pretty straight forward:

UPDATE yourtable SET column_a=1 WHERE column_a=4 AND column_b=1;

Upvotes: 1

Related Questions