Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
How to combine multiple queries
Old 07-13-2008, 11:21 PM How to combine multiple queries
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
How do you properly Update more then one SQL row at a time? Like would I go

Update table set row="w.e" where key="w.e" AND set row2="w.e" where key="w.e"

I assume also that its better to update everything in one line so that you are executive fewer queries.

Thanks
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-14-2008, 04:04 AM Re: How to combine multiple queries
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I'm a bit puzzled here, because what you seems to look for is exactly what the update statement does.
Sql is a set oriented language, meaning that your actions are applied to a set of rows.

When you do an update, you say what column should be updated to which vale, and then you filter the rows you want with a "where" clause.

Given your question, I assume that our table is
Code:
row  |  row2  | key
-----+--------+----
w.a  + w.b    + w.e
-----+--------+----
w.c  + w.d    + w.e
Though It's a bit strange to me...
Don't forget that a row is composed by an series of columns.
So, naming your columns row1, row2 and such is mostly disorienting.

Now, about your example, you would write it:
Code:
update table
set row='w.e', row2='w.e'
where key='w.e'
To update the column "row1" and "row2" of every rows (lines) whose key column value is "w.e"
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-14-2008, 04:39 AM Re: How to combine multiple queries
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Ya I was just asking how to set more than one thing at once, I guess my description was pretty bad but your answer was great. Thanks!
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
Old 07-14-2008, 03:28 PM Re: How to combine multiple queries
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Update Table Set Target_Column_N = Target_Value_N Where Condition_Is_Met

You can adjust the where criteria to decide which rows will be updated. You could say WHERE ID = 1 and only get 1 row, or you could say WHERE ID IN (1, 2) and get 2 rows. Or you can say WHERE CREATED_DATE BETWEEN '1/1/08' AND '12/31/08' and get a whole bunch of rows.

Then you adjust the SET X = Y part to decide what values get applied to all those rows you're changing.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to combine multiple queries
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25461 seconds with 12 queries