LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-08-2004, 10:18 AM   #1
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Rep: Reputation: 30
SQL: making queries from multiple tables


I have never encountered a similar situation before, and I cannot find relative documentation:

Suppose I have two tables. For simplicity, suppose that on one table (which is temporary) I have these columns: name, votes

And suppose that on the other table i have: name, total_votes, and other updated details (this table is a permanent up2date version of first table).

My aim is that for each name in table 1, I grab the relative "votes" value and inject it in Table 2 with the matching "name" column replacing the previous "total_votes' value...

How can I do it?
 
Old 01-08-2004, 12:17 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
call your temp table t and your perm table p

update t,p set p.TotVotes=t.Votes where t.Name=p.Name;

you might even be able to do

update p set p.TotVotes=t.Votes join t using (Name);

<edit>

if you wanted to add votes to total votes then obviously replace "p.TotVotes=t.Votes" with "p.TotVotes=p.TotVotes+t.Votes"

</edit>

Last edited by kev82; 01-08-2004 at 12:19 PM.
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL: tables and queries in school project cold Programming 1 10-29-2005 08:58 PM
seaching by SQL queries jonaskoelker LQ Suggestions & Feedback 6 05-27-2005 10:52 AM
JSP: sql queries markus1982 Programming 0 11-05-2003 06:20 AM
php post data sql queries... bulliver Programming 2 01-03-2003 03:18 AM
sql queries in C program dnewman5 Programming 0 09-14-2001 02:34 PM


All times are GMT -5. The time now is 07:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration