ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 9th, 2005, 08:37 PM
NightVa NightVa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 67 NightVa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 31 m 33 sec
Reputation Power: 5
Can I join TWO tables in one UPDATE query?

Hi all,

I have to update the data in one table but I need to join two tables in the UPDATE query so the correct data gets updated.

I'm not aware of how to update more than one table at one time or in this case pull data from one table that is used to point to another table that needs the update.

I want to update a record but in order to normalize the tables I had to put the "record for content" and the "record for the gym" that uses that content in seperate tables. Now I need to join the two to make an update in the one content table.

Make sense? Help!

Nathan

Reply With Quote
  #2  
Old May 10th, 2005, 08:06 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 13 h 30 m 17 sec
Reputation Power: 53
I think it's possible but have never needed to do it before. You might try asking in one of the SQL forums.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old May 10th, 2005, 11:01 AM
NightVa NightVa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 67 NightVa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 31 m 33 sec
Reputation Power: 5
Did I fail to nomarlize the tables correctly? I thought normalizing would make my queries easier...

I have a connect table and a page content table. In a standard select querie I would simply join the two to grab a specific record.

How owuld I update records using the same structure? I thought breaking data down into 'atomic' structures would make things easier.

Nathan

Reply With Quote
  #4  
Old May 10th, 2005, 11:14 AM
CfFreelancer CfFreelancer is offline
CF Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Long Island, NY
Posts: 34 CfFreelancer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 29 m 50 sec
Reputation Power: 5
kiteless is right, you'll prob have more luck in a sql forum but see if this helps

http://forums.devshed.com/t36686/s.html&highlight=update+query+join+tables

Reply With Quote
  #5  
Old May 10th, 2005, 11:29 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 13 h 30 m 17 sec
Reputation Power: 53
I've always just done it as two queries within a <cftransaction> block.

Reply With Quote
  #6  
Old May 10th, 2005, 09:59 PM
NightVa NightVa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 67 NightVa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 31 m 33 sec
Reputation Power: 5
I see, but what do those two queries look like? I would appreciate an example as I'm a visual learner.

I can then adapt what you show as an example to what I'm doing.

Nathan

Reply With Quote
  #7  
Old May 10th, 2005, 11:07 PM
flashbck's Avatar
flashbck flashbck is offline
/* Spawn Killer Killer */
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Nov 2004
Location: New Orleans, LA, USA
Posts: 1,145 flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)flashbck User rank is First Lieutenant (10000 - 20000 Reputation Level)  Folding Points: 3924 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 19 h 34 m 34 sec
Reputation Power: 203
what SQL server are you running? MSSQL? Oracle? MySQL?, PostgreSQL?

Reply With Quote
  #8  
Old May 11th, 2005, 08:35 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 13 h 30 m 17 sec
Reputation Power: 53
Quote:
Originally Posted by NightVa
I see, but what do those two queries look like? I would appreciate an example as I'm a visual learner.

I can then adapt what you show as an example to what I'm doing.

Nathan
I'm not sure I understand...it would just be two update statements, but by wrapping them in <cftransaction> you force it to succeed or fail as a single unit. Like:



<cftransaction>

<cfquery name="query1" dsn="dsn">

UPDATE table1

SET column_name = new_value

WHERE column_name = some_value

</cfquery>

<cfquery name="query2" dsn="dsn">

UPDATE table2

SET column_name = new_value

WHERE column_name = some_value

</cfquery>

</cftransaction>

Reply With Quote
  #9  
Old May 12th, 2005, 09:36 AM
NightVa NightVa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 67 NightVa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 31 m 33 sec
Reputation Power: 5
I received this response from the Database forums.



update table1
inner
join table2
on table1.keyfld = table2.keyfld
set table1.fldx = table2.fldy
where table2.fldz = 'foo'



Does it look like it makes sense?

Nathan

Reply With Quote
  #10  
Old May 12th, 2005, 09:52 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 13 h 30 m 17 sec
Reputation Power: 53
It seems to make sense. The question is really: does it work?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Can I join TWO tables in one UPDATE query?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway