Combine 2 Select statements into 1 Select Statement

In my Oracle open query statement,  I need to get the MIN(GPCOMP1.GPPROBLOG.CREATED_ON) to put into a field of a work SQL table.
I also get another MIN(GPCOMP1.GPPROBLOG.CREATED_ON) to put into another field of the work table.
Is there a way to combine both statements into 1 statement and still get me the correct MIN(GPCOMP1.GPPROBLOG.CREATED_ON).
They work fine separately.

I do it this way because,  if StatusDateMinMax winds up being null for a particular record, then I need to use the date in StatusDateMin.
If both dates are Null then the report will just display a blank.

I use a Open Query in a SQL Store Procedure in order to read and retrieve records from Oracle tables.



(  SELECT MIN(GPPROBLOG.CREATED_ON) From GPPROB, GPPROBLOG
                            WHERE 0000010007 = GPPROB.Custno and 13603 = GPPROB.Group_ID AND GPPROB.STATUS = GPPROBLOG.STATUS                                                                
                               and GPPROBLOG.CREATED_ON >= ( Select Max(GPPROBLOG.CREATED_ON) From GPPROB, GPPROBLOG  
                             WHERE 0000010007 = GPPROB.Custno and 13603 = GPPROB.Group_ID AND GPPROB.STATUS <> GPPROBLOG.STATUS )  ) as StatusDateMinMax,
                                          
                                          
                   (   SELECT MIN(GPPROBLOG.CREATED_ON) From GPPROB, GPPROBLOG  
                             WHERE 0000010007 = GPPROB.Custno and 13603 = GPPROB.Group_ID AND GPPROB.STATUS = GPPROBLOG.STATUS  ) as StatusDateMin,
thayduckProgrammer AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

awking00Information Technology SpecialistCommented:
I'm having a little trouble trying to visualize the kind of created_on dates that can vary in the two queries obviously based on the various status values in the two tables. Can you produce some sample relevant data (i.e. custno, group_id, status, and created_on values) for the two tables and what you expect as a result?
slightwv (䄆 Netminder) Commented:
Double check this query:
Select Max(GPPROBLOG.CREATED_ON)
From GPPROB, GPPROBLOG  
WHERE 0000010007 = GPPROB.Custno and 13603 = GPPROB.Group_ID AND GPPROB.STATUS <> GPPROBLOG.STATUS

I believe this creates a Cartesian join and can return GPPROBLOG statuses that are from any custono and group.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flow01Commented:
And  0000010007   and 13603 in the example are  not hardcoded  i assume?  
In real live do they refer to values from data retrieved by the main query or  to values passed as an argument to the query.
And how many rows are there in GPPROBLOG : i don't see a join condition indicating certain GPROBLOG 'belong'  to a GRPROB .
And  CREATED_ON  does it contains dates or times ?
(select count(*) from GPPROBLOG where trunc(CREATED_ON) <> CREATED_ON  -- if non zero it contains(also) times
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.