Solved

MySQL query - change the value of a field in multiple id's

Posted on 2008-10-27
2
1,114 Views
Last Modified: 2012-06-27
Hi,

The last half an hour has confirmed to me that I know so little when it comes to MySQL.  I have been trying to update the value of a column (guest_account) in a table (customers) where guest_account = NULL.  The updated value should be 0.  In other words, in the customers table, change the value of all entries in the guest_account column/field from NULL to 0, but only if they equal NULL.

Here's what I thought would work (but doesn't):
UPDATE `customers` SET `guest_account` = '0' WHERE `guest_account` = NULL;

Open in new window

0
Comment
Question by:Treder
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22817303
NULL is special, but you where close:

UPDATE `customers` SET `guest_account` = '0' WHERE `guest_account` IS  NULL;

Open in new window

0
 

Author Comment

by:Treder
ID: 22817419
You're an angellll :) Sorry for the cliche!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now