Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I fix this query - subqueries and max fields?

Re: How do I fix this query - subqueries and max fields?

From: DA Morgan <damorgan_at_psoug.org>
Date: Thu, 13 Oct 2005 16:39:45 -0700
Message-ID: <1129246770.391409@yasure>


Charles wrote:
> I'm querying max values of 2 date fields from 2 different tables :
> location and elev, and also a field called NOTE...and joining them
> using the PID field. The query below is working.
>
> SELECT NOTE, (SELECT MAX(A.DATE1) FROM LOCATION A WHERE A.PID =
> LOCATION.PID) AS MAXDATE1, (SELECT MAX(A.DATE2) FROM ELEVATION A
> WHERE A.PID = ELEVATION.PID) AS MAXDATE2 FROM LOCATION, ELEVATION WHERE
> LOCATION.PID = ELEVATION.PID;
>
> However, if I try to query more fields including the PID,in addition to
> what's listed above, the query does not work. Any suggestions?
>
> SELECT LOCATION.PID AS PTID, NOTE,NOTE2,NOTE3,NOTE4, (SELECT
> MAX(A.DATE1) FROM LOCATION A WHERE A.PID = LOCATION.PID) AS MAXDATE1,
> (SELECT MAX(A.DATE2) FROM ELEVATION A WHERE A.PID = ELEVATION.PID) AS
> MAXDATE2 FROM LOCATION, ELEVATION WHERE LOCATION.PID = ELEVATION.PID;
Turn this into an in-line views:

SELECT a.col1, b.col2, c.col3, c.col4
FROM (query1) A, (query2) B, sometable C WHERE ...

-- 
Daniel A. Morgan
http://www.psoug.org
damorgan_at_x.washington.edu
(replace x with u to respond)
Received on Thu Oct 13 2005 - 18:39:45 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US