This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SQL query problem with MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL query problem with MySQL" Watch "SQL query problem with MySQL" New topic

SQL query problem with MySQL

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Hi guys,

I have a table called 'USER', I've just added a new colum (attribute) called regDate (type varchar).

Now all the existing records have regDate set to NULL, what I want to do is change all the NULL values to some date. My query is as follow

UPDATE USER SET regDate = '19/07/2007 1.11pm' WHERE regDate = NULL;

This doesn't unfortunatley update all the NULL columns with the date.

I suspect it's due to me using regDate twice in the query, but I cant see how else I could update all the columns.
So my questions, is my query correct? Is there a better way of writing this query so I can update the relevant columns?

I'm using MySQL db.

Thanks for your thoughts,
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

I don't know MySQL very well, but usually in SQL a field is null but is not equal to null. Try:

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Fabulous Paul, works like a charm.

Thank you very much. Much appreciated.
I agree. Here's the link:
subject: SQL query problem with MySQL
It's not a secret anymore!