473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

UPDATE from COUNT(*) of another table in DB2 - HOW?

I'm trying to update a new field in a table from a COUNT(*) of Registration IDs grouped by Course IDs.

COUNT: Course_ID
11 1234
12 2323
19 8932

I want to populate a NUM_REG field in another table with the COUNT from this query to the records that have matching Course_IDs.

Similar to this situation:
Expand|Select|Wrap|Line Numbers
  1. update a 
  2. set a.cnt = b.cnt 
  3. from table2 a, 
  4.         (select widget_type, count(*) as cnt 
  5.          from table1 
  6.          group by widget_type) b 
  7. where a.widget_type = b.widget_type 
  8.  
Only problem is, that code will not work in DB2, keeps giving me an error about unexpected token after the beginning of the statement.

Any suggestions?
Feb 28 '07 #1
1 6403
Snib
24
I do not have Db2 running on my server to try this SQL but you should be able to do it with something like:

update table2 as a
set a.cnt = (Select count(*)
from table1 as b
where a.widget_type = b.widget_type)

Regards

Snib
Mar 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Caroline | last post by:
I need to update a table by copying a column from another table (having the same structure, but on another database), from the record having the same primary key. 1 - What is the correct...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
9
by: Deja User | last post by:
This is probably very simple but I can't figure out a way to update one table from another table. Here is an example: ------ TABLEA ------ first_name last_name
3
by: deko | last post by:
I know I can use Inner Joins in an Update query like this: UPDATE DISTINCTROW tblA INNER JOIN qryA ON tblA.SomeID = qryA.SomeID SET Flag = 0 WHERE (Flag = -1); But I am specifying the new...
3
by: Chris Morton | last post by:
Not sure if this is the right location for this question. I Saw several previous FP questions in this Group and did not see one for VFP.... If this is the wrong group, please direct me...
3
by: Yakimo | last post by:
Hi I am trying to append some records form tmpSource to tmpDest table using datasets Tables tmpSourec and tmpDest are identical. My setup is the following: - daSource - data adapter for...
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
4
by: BulbFresh | last post by:
Hi, I'm using Access 2007. I have imported a table called 'January' and from this I need to update an existing table called 'TablesInfo' which needs to hold some details about the imported...
1
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I've got a table where I store tips for a challenge. Its structure is this: tip_id, challenge_id, user_id, ip_address, tip_date, tip_text The tips can be voted up or down, I store vote data in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.