Solved

MySQL / Cloudscape

Posted on 2006-11-07
4
288 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Creating and Managing Databases with phpMyAdmin in cPanel.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

17 Experts available now in Live!

Get 1:1 Help Now