Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make an UPDATE SELECT query?

Status
Not open for further replies.

jgannaway

Programmer
Jan 28, 2005
4
US
I have a LOG table that has a filed named "folder_reset". If it's equal to 1, then the folder has been reset.

A folder gets reset when a user clicks a button (button_id). A reset button can reset multiple folder_id's.

I built a refernce table named "folder_reset" that links button_ids with the folder_ids that they will reset.

Code:
LOG TABLE
---------
log_id   order_id   folder_id   folder_reset
1        2000       1           0
2        2000       2           0
3        2000       3           0

LOG_RESET TABLE
---------------
reset_id   button_id   folder_id
1          300         1
2          300         2

So, when the button_id 300 is clicked, I want the LOG TABLE to look like this:

Code:
LOG TABLE
---------
log_id   order_id   folder_id   folder_reset
1        2000       1           1
2        2000       2           1
3        2000       3           0

The UPDATE part of the query would look like:

UPDATE log
SET fodler_reset = 1 WHERE order_id = 2000
AND...

And the SELECT part of the query would look like:

SELECT folder_id
FROM log_reset
WHERE button_id = 300

However, I have no idea how to do an UPDATE... SELECT statement. Any advice would be much appreciated!

Thanks in advance!
-Jeff

"Grace... She travels outside of Karma"
-U2
 
What do you mean and Update.. select statement? I belive you will need 2 separate sql statements..

JIm
 
Jim...

Thanks for the offer to help. I just figured out what I wanted:

UPDATE log
SET fodler_reset = 1
WHERE order_id = 2000
AND folder_id IN
(
SELECT folder_id
FROM log_reset
WHERE button_id = 300
)

Hope this helps someone else in the future.

Thanks all!
-Jeff

"Grace... She travels outside of Karma"
-U2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top