logo       

Re: SQL syntax: msg#00454

Subject: Re: SQL syntax
On Wed, 31 Jul 2002, Mindaugas Riauba wrote:

>
>   I have two similar tables with host and services availability
> data (Nagios). And I want to find out services which are not OK
> in first table and OK in second one. Query I used is:
>
> select c.* from coll_servicestatus as c inner join
> servicestatus as s on (c.service_description=s.service_description
> and c.host_name=s.host_name) where c.service_status != 'OK' and
> s.service_status = 'OK';
>
>   Results are fine. But how to write UPDATE statement if I want
> to set those non-OK states in first table to OK if they are OK
> in the second table?
>
>   Something like:
>
> update coll_servicestatus set service_status = 'OK' from
> coll_servicestatus as c, servicestatus as s where
> c.service_description = s.service_description and c.host_name=s.host_name
> and c.service_status != 'OK' and s.service_status = 'OK';
>
>   updates all rows not only required ones.

There are two joins on coll_servicestatus in the above, the one in the
from and one with the updating table.  You could probably remove the
coll_servicestatus as c, and change references to c to coll_servicestatus
or use a subselect, something like:

update coll_servicestatus set service_status='OK' where
service_status!='OK' and exists (select * from servicestatus as s where
coll_servicestatus.service_description=s.service_description and
coll_servicestatus.host_name=s.host_name and s.service_status='OK');


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@xxxxxxxxxxxxxx



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe