+ 2

How to give if condition in SQL query

I'm using python to store values inside SQL table. I need to insert some values into the table. That table consists of 4 columns. But the condition is in the last two columns, if the 3rd column has value then the 4th should be set to zero and vice versa. How can I do this? Please help me

17th Aug 2020, 11:49 AM
Pavithra Velusamy
Pavithra Velusamy - avatar
3 Respuestas
+ 8
Update tablename set 4th-column=0 where (select 3rd-column from tablename where value=" ") I haven't tried updating whole column to 0 but just give a try on this! just a thought(u can drop other then setting it to 0 right?)
17th Aug 2020, 12:09 PM
chaithra Gowda
chaithra Gowda - avatar
+ 8
Ohh!....I thought you will search for a particular value in 3rd column if it exists...then u will set whole 4th column to zero Drop means delete the column 4 fully
19th Aug 2020, 11:05 AM
chaithra Gowda
chaithra Gowda - avatar
+ 1
Thanks! I'll try this. (I don't exactly get what you meant by "drop other then") It's actually a method which we will be in loop. So each time it will add value to 3rd or 4th. So if the first time it is added to 3rd, then the second time it might add the value to 4th column of the same row. I don't know whether this explanation is clear
19th Aug 2020, 9:41 AM
Pavithra Velusamy
Pavithra Velusamy - avatar