Solved

MySQL / Cloudscape

Posted on 2006-11-07
4
293 Views
Last Modified: 2007-12-19
Hi,

I would like to run a trigger in cview on cloudscape but am having some difficulty in writing the correct sql.

I have a table 'patient' which has a field 'hcsID'. In this field there is an int (either 1,2,3,4,5). This defines which staff is dealing with which patient.

In the 'HCStaff' table there is a field 'total_patients'. I want this field to be updated depending on what value is in hcsID in the patient table.

my attempt so far is:
update HCStaff set total_patients = select count(hcsID) from patient group by HCSID

I think I have the right idea but cannot further this.

Any help is appreciated.

Thanks,
Pete
0
Comment
Question by:pete420
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17890570
How about...

UPDATE HCStaff
INNER JOIN (SELECT COUNT(hcsID) total, HCSID FROM patient GROUP BY HSID) tblX ON (HCStaff.HCSID = tblX.HCSID)
SET HCStaff.total_patients = tblX.total
0
 

Author Comment

by:pete420
ID: 17890741
Hi,

Thanks for the quick reply.

First off, just notices I posted in the MySQL section by mistake. Meant to post in a more general area as this is JDBC/sql


I tried your solution above but cview is complaining about the word INNER. Strange as it does support inner joins.


0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 200 total points
ID: 17890816
Huh.  You might try it without the "INNER" (JOIN by itself is sufficient).

If its problem is it doesn't like doing an UPDATE with a JOIN involved, then a different solution may be in order.  I wonder if the following would work:

UPDATE HCStaff SET total_patients = (SELECT COUNT(hcsID) FROM patient WHERE HSID = HCStaff.HCSID);
0
 

Author Comment

by:pete420
ID: 17890853
Hi,

I had already tried it without INNER with no success.

However, your second solution is spot on.

Thanks very much!


Pete
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now