?
Solved

MySQL / Cloudscape

Posted on 2006-11-07
4
Medium Priority
?
307 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 800 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 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