Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:25:15+00:00 2026-06-14T22:25:15+00:00

below is my sql statement, everything work fine just i dont know how to

  • 0

below is my sql statement, everything work fine just i dont know how to find the MAX from multiple return value. anyway here is my code, the part i having problem is marked with [].

SELECT 
(product1.CNT+product2.CNT+product3.CNT)AS CNT,
(
 IFNULL(product1.SUMAMT,0)+
 IFNULL(product2.SUMAMT,0)+
 IFNULL(product3.SUMAMT,0)
)AS AMTAMT,

[ MAX(product1.MXDT, product2.MXDT, product3.MXDT)AS MAXDT ]

FROM 

(SELECT 
 SUM(LAMT)AS SUMAMT, 
 COUNT(LAMT)AS CNT,
 IFNULL(LSUBDT,(CURDATE()-INTERVAL 9999 DAY))AS MXDT
 FROM product1 WHERE LSUBBY=1 AND RECST=1
)product1 

CROSS JOIN 
(SELECT 
 SUM(LAMT)AS SUMAMT, 
 COUNT(LAMT)AS CNT,
 IFNULL(LSUBDT,(CURDATE()-INTERVAL 9999 DAY))AS MXDT
 FROM product2 WHERE LSUBBY=1 AND RECST=1
)product2

CROSS JOIN 
(SELECT 
 SUM(LAMT)AS SUMAMT, 
 COUNT(LAMT)AS CNT,
 IFNULL(LSUBDT,(CURDATE()-INTERVAL 9999 DAY))AS MXDT
 FROM product3 WHERE LSUBBY=1 AND RECST=1
)product3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:25:16+00:00Added an answer on June 14, 2026 at 10:25 pm

    The function you’re looking for is called GREATEST:

    ...
    GREATEST(product1.MXDT, product2.MXDT, product3.MXDT) AS MAXDT
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do the below sql statement in GORM select * from table1
I want to write an SQL statement like below: select * from tbl where
Can anyone please explain the below SQL statement from Oracle DB: select decode(TRIM(to_char(SYSDATE,'Day')),'Monday','3','1') from
The SQL statement below used to work a few years ago, now it doesn't
I have to read the below SQL statement from one properties. update scoreconfig set
I'm trying to figure out why the below SQL statement does not return the
The sql statement below will not run in SQLite: select * from A left
In the below sql statement i get the following error Cannot use an aggregate
I'm getting the error below for this SQL statement in VB.Net 'Fill in the
I'm writing an sql statement (see below) which compares 2 serial numbers on 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.