We help IT Professionals succeed at work.
Get Started

Rewrite SQL Statement for Most Recently Updated Rows

283 Views
Last Modified: 2012-05-09
How can I rewrite the following SQL statement so that I only get the rows that have the most recent update?

ie. I have:
WName1  FmName1  1000  6/29/2010
WName1  FmName1  1026  6/30/2010

I only want to see "WName1  FmName1  1026  6/30/2010" returned

SELECT CD_WELL.well_common_name, CD_WELLBORE_FORMATION.formation_name, CD_WELLBORE_FORMATION.prognosed_md + {fn IFNULL(CD_DATUM.datum_elevation, 0)}, CD_WELLBORE_FORMATION.update_date FROM CD_WELL, CD_WELLBORE_FORMATION, CD_SITE, CD_DATUM WHERE (UPPER(CD_SITE.site_name) LIKE UPPER('%" & TextPadName.Text & "%')) AND (CD_WELL.well_id = CD_WELLBORE_FORMATION.well_id) AND (CD_WELL.site_id = CD_SITE.site_id) AND (( ( {fn UCASE( CD_DATUM.is_default )} = 'Y' ) OR ( CD_DATUM.datum_id IS NULL ) OR ( {fn CONCAT (CD_DATUM.well_id, CD_DATUM.datum_id)} IN ('03q2DecAl4nlEgX', '86zNT2KSuII6yfH', '8drumnJseey3L5f', '966uBIK5Xhtos05', 'aaIx5gNxghWGqO0', 'AXm50zSOPrgZsZ8', 'dOBDPIleVGuPdj9', 'e2qQjvwmitACVhA', 'e7aRS7VfTwfciQ1', 'FUtaJlUXErY5Qiy', 'iOVCMPIgTeX7Dub', 'JC1Rm8EZ9HmGttJ', 'lsZtTPuanusLIL9', 'ntfL8vG8VsoG82r', 'rvPgl6F83dhPqcZ', 'RwGi6bVLL6W2d2i', 'SJog0u94MuVqjWN', 'sSKqoFU4uaSbrde', 'uttJBp2CsFxWI9W', 'uWUtReyLy1h2WFd', 'wJbDqiXc1wcEPQw', 'ww39g31VygDulen', 'YWwMjlUFn0WNMVP', 'ZILDpIPYMHfWqVj') )) AND (CD_WELL.well_id = CD_DATUM.well_id)) ORDER BY 4 DESC

Open in new window


SELECT CD_WELL.well_common_name, CD_WELLBORE_FORMATION.formation_name, CD_WELLBORE_FORMATION.prognosed_md + {fn IFNULL(CD_DATUM.datum_elevation, 0)}, CD_WELLBORE_FORMATION.update_date FROM CD_WELL, CD_WELLBORE_FORMATION, CD_SITE, CD_DATUM WHERE (UPPER(CD_SITE.site_name) LIKE UPPER('%" & TextPadName.Text & "%')) AND (CD_WELL.well_id = CD_WELLBORE_FORMATION.well_id) AND (CD_WELL.site_id = CD_SITE.site_id) AND (( ( {fn UCASE( CD_DATUM.is_default )} = 'Y' ) OR ( CD_DATUM.datum_id IS NULL ) OR ( {fn CONCAT (CD_DATUM.well_id, CD_DATUM.datum_id)} IN ('03q2DecAl4nlEgX', '86zNT2KSuII6yfH', '8drumnJseey3L5f', '966uBIK5Xhtos05', 'aaIx5gNxghWGqO0', 'AXm50zSOPrgZsZ8', 'dOBDPIleVGuPdj9', 'e2qQjvwmitACVhA', 'e7aRS7VfTwfciQ1', 'FUtaJlUXErY5Qiy', 'iOVCMPIgTeX7Dub', 'JC1Rm8EZ9HmGttJ', 'lsZtTPuanusLIL9', 'ntfL8vG8VsoG82r', 'rvPgl6F83dhPqcZ', 'RwGi6bVLL6W2d2i', 'SJog0u94MuVqjWN', 'sSKqoFU4uaSbrde', 'uttJBp2CsFxWI9W', 'uWUtReyLy1h2WFd', 'wJbDqiXc1wcEPQw', 'ww39g31VygDulen', 'YWwMjlUFn0WNMVP', 'ZILDpIPYMHfWqVj') )) AND (CD_WELL.well_id = CD_DATUM.well_id)) ORDER BY 4 DESC
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE