Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-08-2004, 09:18 AM   #1
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, 11:17 AM   #2
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
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);


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


Last edited by kev82; 01-08-2004 at 11:19 AM.


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 07:58 PM
seaching by SQL queries jonaskoelker LQ Suggestions & Feedback 6 05-27-2005 09:52 AM
JSP: sql queries markus1982 Programming 0 11-05-2003 05:20 AM
php post data sql queries... bulliver Programming 2 01-03-2003 02:18 AM
sql queries in C program dnewman5 Programming 0 09-14-2001 01:34 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:03 PM.

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