[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

MySQL / Cloudscape

Posted on 2006-11-07
4
Medium Priority
?
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 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