0

Good day, I have a simple question here where I want to update my column whenever these two value are used.

UPDATE products SET description='YES' WHERE description='PENDING'

other than 'PENDING', I also want 'NO' to be included in this query for update.

What can I do? I want it to be updated on any row I update/click, Thank you.

0

3 Answers 3

1
update products
set description = 
case 
when description='PENDING' then 'YES'
else 'NO'
end
Sign up to request clarification or add additional context in comments.

Comments

0

Are you looking for st. like this?

UPDATE products 
SET description='YES' 
WHERE description IN ('PENDING','NO') AND
      id = 3

It sets description="YES" to all rows where description is equal to PENDING or NO.

9 Comments

Hi, @panther, yeah, it's almost what I want, but it changes all the row. I just want that particular row to change.
Just add second condition, I updated my answer. For exaple row ID, or st. else what´s is unique for row you want to change.
What if I want every distinct id to be able to change, not only a single one like declared above? Whenever I click on any of the row, and only that row will change, and others also.
I don´t know what you want... For changing single row (or more rows using more IDs in query) use my code, if you want to change ALL rows, just leave id=3. Do you want to change multiple lines, which lines? How to define them?
I want to change one value in the row, without affecting the whole column. for example, I want pending of that row change into yes, the other data in the column remain the same.
|
0

try below:

UPDATE products SET description=if(<Your Condition to set Value YES>,'YES','NO') WHERE description='PENDING'

6 Comments

I want it to be able to update each 'pending' and change it to 'yes' or 'no' for each row, not update all the column data.
@Confuser.. I have updated answer. What is your condition to set description "Yes" or "NO"
my condition is different id? is it possible? for different id, set yes to replace the pending. So it won't update the whole column with same pending value.
What do you mean by different id? Please explain more
Means, every single row with different id, I'll be able to change it individually, not change "yes" and all became "yes".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.