aspose file tools*
The moose likes JDBC 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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL query problem with MySQL" Watch "SQL query problem with MySQL" New topic
Author

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,
Regards
Zein
Paul Sturrock
Bartender

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.
Zein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL query problem with MySQL
 
Similar Threads
editing values in the jsp and updating the table
Problem with UPDATE statement in HSQLDB
sql query between two dates
sql query between two dates
Question about executeUpdate and MySQL