SQL Guru's - Great Lakes 4x4. The largest offroad forum in the Midwest

Go Back   Great Lakes 4x4. The largest offroad forum in the Midwest > General 4x4 Stuff > The Pub
GL4x4 Live! GL4x4 Casino

The Pub A friendly forum where everybody is nice, and will answer any questions you have about life.

greatlakes4x4.com is the premier Great Lakes 4x4 Forum on the internet. Registered Users do not see the above ads.
Search
Reply
 
Thread Tools Search this Thread
Old December 28th, 2007, 03:59 PM   #1
Jeeperz Creeperz
Senior Member
 
Jeeperz Creeperz's Avatar
 
Join Date: 11-08-05
Location: Wyandotte, MI
Posts: 3,120
iTrader: (13)
Mentioned: 1 Post(s)
Send a message via ICQ to Jeeperz Creeperz Send a message via AIM to Jeeperz Creeperz Send a message via MSN to Jeeperz Creeperz Send a message via Yahoo to Jeeperz Creeperz
Default SQL Guru's

I need an SQL statement to set a value in one table, based upon a value in another table where the tables both share a value which is neither of the aforementioned ones.

Get it?

Something along the lines of:

update table1 set value1 = 'xxxxx' where table1.value2 = table2.value3
Jeeperz Creeperz is offline   Reply With Quote
Sponsored Links
Advertisement
 
Old December 28th, 2007, 05:37 PM   #2
Hacksaw
WWSD - What would stan do
 
Hacksaw's Avatar
 
Join Date: 11-04-05
Location: Isle Of TREASURE, FL
Posts: 11,204
iTrader: (5)
Mentioned: 12 Post(s)
Default

thats the correct statement

UPDATE table_name
SET column_name = new_value
WHERE table_name1.column1= table_name2.column1
Hacksaw is offline   Reply With Quote
Old December 29th, 2007, 09:06 AM   #3
Jeeperz Creeperz
Senior Member
 
Jeeperz Creeperz's Avatar
 
Join Date: 11-08-05
Location: Wyandotte, MI
Posts: 3,120
iTrader: (13)
Mentioned: 1 Post(s)
Send a message via ICQ to Jeeperz Creeperz Send a message via AIM to Jeeperz Creeperz Send a message via MSN to Jeeperz Creeperz Send a message via Yahoo to Jeeperz Creeperz
Default

Quote:
Originally Posted by HackSaw View Post
thats the correct statement

UPDATE table_name
SET column_name = new_value
WHERE table_name1.column1= table_name2.column1
Sort of, but I'm looking to get a value from table2 which is specific to table 2 but table1 and table 2 both share the same value in column1.

UPDATE table1
SET column1 = new_value
WHERE table2.column4 = value AND table1.column1 = table2.column1

Is that valid?
edit: no, "Unknown table 'table2' in where clause"

Last edited by Jeeperz Creeperz; December 29th, 2007 at 09:10 AM.
Jeeperz Creeperz is offline   Reply With Quote
Old December 29th, 2007, 10:48 AM   #4
Hacksaw
WWSD - What would stan do
 
Hacksaw's Avatar
 
Join Date: 11-04-05
Location: Isle Of TREASURE, FL
Posts: 11,204
iTrader: (5)
Mentioned: 12 Post(s)
Default

Quote:
Originally Posted by Jeeperz Creeperz View Post
Sort of, but I'm looking to get a value from table2 which is specific to table 2 but table1 and table 2 both share the same value in column1.

UPDATE table1
SET column1 = new_value
WHERE table2.column4 = value AND table1.column1 = table2.column1

Is that valid?
edit: no, "Unknown table 'table2' in where clause"
hahah
Sorry, im retarded.

UPDATE table1
SET table1.column1 = new_value
WHERE table1.colmun1 in (select column2 from table2
where table2.column4 = value);


Try that.
Hacksaw is offline   Reply With Quote
Old December 29th, 2007, 12:26 PM   #5
Jeeperz Creeperz
Senior Member
 
Jeeperz Creeperz's Avatar
 
Join Date: 11-08-05
Location: Wyandotte, MI
Posts: 3,120
iTrader: (13)
Mentioned: 1 Post(s)
Send a message via ICQ to Jeeperz Creeperz Send a message via AIM to Jeeperz Creeperz Send a message via MSN to Jeeperz Creeperz Send a message via Yahoo to Jeeperz Creeperz
Default

Quote:
Originally Posted by HackSaw View Post
hahah
Sorry, im retarded.

UPDATE table1
SET table1.column1 = new_value
WHERE table1.colmun1 in (select column2 from table2
where table2.column4 = value);


Try that.
Here's a more detailed breakdown....

table1.column1 = table2.column1 (they contain the same data, but I don't know what it is)

table1.column2 = value to be set (to a fixed known value)

table2.column2 = known data value (I can get table2.column1 data using this value)

So:

UPDATE table1.column1 = 'xxxxx'
WHERE table2.column2 = 'yyyyy'
AND table1.column1 = table2.column1

something along those lines.
Jeeperz Creeperz is offline   Reply With Quote
Old December 29th, 2007, 01:14 PM   #6
Monkeyevil
I <3 Miatas
 
Monkeyevil's Avatar
 
Join Date: 11-05-05
Location: Kalamazoo, MI
Posts: 8,987
iTrader: (16)
Mentioned: 2 Post(s)
Send a message via AIM to Monkeyevil
Default

My little hacksaw is growing up!
__________________
JcrOffroad
Zoom Zoom!
Monkeyevil is offline   Reply With Quote
Reply
Great Lakes 4x4. The largest offroad forum in the Midwest > General 4x4 Stuff > The Pub

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

Forum Jump


All times are GMT -5. The time now is 11:41 PM.


Powered by: vBulletin, Copyright 2000 - 2012, Jelsoft Enterprises Ltd.
User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd. Runs best on HiVelocity Hosting.
Page generated in 0.12122 seconds with 39 queries