× 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.



On 14 Dec 2012 13:02, Steve Richter wrote:
someone posted about sql lateral recently, which I had never heard
of. Here is my first use of it.

There are 2 files. A header and a detail. Header contains the BOL
number. The detail contains the ship date of all the lines of that
BOL. ( go figure )

Here is the sql that shows the BOL and its ship date:

select a.w1BOL, b.w2sdte
from w1mast a
, lateral ( select c.w2sdte
from w2mast c
where a.w1wacd = c.w2wacd and a.w1sid = c.w2sid
and c.w2sdte<> 0
fetch first row only ) b
where a.w1wacd = 'LAE' and a.w1BOL<> ''

I figure without lateral I have to do a join with group by and
MIN(w2sdte) to eliminate the multiple detail rows. But with lateral I
can use "fetch first row only" which is clearer to read since it does
exactly what I want to be done.


I suspect the LATERAL specification is moot for the given SQL. I expect that the /same/ SQL, but without the LATERAL keyword, will function just fine; no errors, and the identical output\effect. It is the NTE which allows the FETCH FIRST 1 ROW ONLY, not the use of LATERAL.

The Nested Table Expression (NTE) [aka Derived Table] has often been shown in examples on this list. The LATERAL in the syntax diagram is optional [mostly]; i.e. nothing in the above example would seem to imply any requirement for its specification. If there is a reference to the correlation identifier A in the column\expression-list of the SELECT in the NTE, then in my understanding and experience, the LATERAL keyword would be required.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.