× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




t is defined in the with clause. It's base is myfile, same as a.

Try it like this:

delete from myfile a where exists

(select 1 from (select fld1, fld2, fld3, max(fld4) lmax from myfile t
join otherfile m on t.fld1 = m.fld1 and t.fld2 = m.fld2 group by fld1,
fld2, fld3)z

where and a.fld1 = z.fld1 and a.fld2=z.fld2 and a.fld3= z.fld3 and
a.fld4 = z.lmax)

That's going to be pretty inefficient, I'd reorganize it some, but it
keeps a lot of the original so you can see how it lines up.

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Dennis Lovelady
Sent: Wednesday, March 31, 2010 10:01 AM
To: 'Midrange Systems Technical Discussion'
Subject: RE: SQL Delete from table where rows found in a join

with t as (
SELECT fld1, fld2, fld3, MAX(fld4) lmax FROM myfile GROUP BY fld1,
fld2, fld3)

select a.* from myfile a join t on
a.fld1=t.fld1 and
a.fld2=t.fld2 and
a.fld3=t.fld3 and
a.fld4=t.lmax
join otherFile m on m.fld1= a.fld1 and m.fld2=a.fld2
where a.fld4 ='.'



this selects the rows from myfile that I want to delete.

I did cut it off. Sorry.

David, this is contrived, obviously since a.fld4 is both alpha and
numeric.
Also unless you have a table named T, you've neglected to supply its
name.
You will also have likely problems with your first join due to using
fld4 instead of lmax (if you can even do that).

But in general, if all else were the same, I would do:
Delete from myfile a where exists
(select 1 from t
Join otherfile m on m.fld1=a.fld1 and m.fld2=a.fld2...
Where t.fld1=a.fld1 and t.fld2=a.fld2 ...
)

Dennis Lovelady
http://www.linkedin.com/in/dennislovelady
--
"Millions long for immortality who do not know what to do with
themselves on a rainy Sunday afternoon."
-- Susan Ertz



--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.