update same table with more than one record

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
theclay7
Forum Commoner
Posts: 50
Joined: Wed Feb 19, 2003 3:17 am

update same table with more than one record

Post by theclay7 »

I have a forum table which I need to perform the following update

1) I have an original message which I need to change its online status into DISABLE 'D' in my "status" field as follow single command:

UPDATE forum SET status = 'D' where message_id = 1 and parent_id is NULL;

*the parent_id field is NULL because it is a parent thread...

However, it has some child threads to this message...therefore I must force the all the child thread to change the status into 'D' also. So I did a second sql query as follow:

UPDATE forum SET status = 'D' where parent_id = 1;

*parent_id = 1 means it points to the parent message_id = 1

My question is

DOES anyone know a good sql query that will combine these two queries into ONE single query?

thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Maybe:

Code: Select all

UPDATE forum SET status = 'D' WHERE (message_id = 1 AND parent_id IS NULL) OR parent_id = 1;
Mac
Post Reply