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 6535491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:22:48+00:00 2026-05-25T10:22:48+00:00

I have two queries at the moment, returning the same data, I want the

  • 0

I have two queries at the moment, returning the same data, I want the second query to run if the first returns no results, here’s the basic idea of my PHP right now:

Run Query1
If Query1 returns a result
    Enter data into array
Else 
    Run Query2
    Enter data into array

What I’m wondering, is can I do that exclusively using Oracle SQL? So it’d just run a single query to the database, do a quick check of the first statement, and if no results are found run the second one?

Thanks

  • 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-05-25T10:22:48+00:00Added an answer on May 25, 2026 at 10:22 am
    QUERY1
    UNION ALL
    QUERY2
    WHERE NOT EXISTS (QUERY1)
    

    e.g:

    SELECT id
      FROM products
        UNION ALL 
    SELECT  id
      FROM old_products
        WHERE NOT EXISTS (SELECT id  FROM products) 
    

    Query:

    SELECT * 
        FROM Table 
    WHERE ID = 7 
        AND Flag = 1
    UNION ALL
    SELECT * 
        FROM Table 
    WHERE ID = 7 
        AND NOT EXISTS (select * from Table where ID = 7 and Flag = 1)
    

    To identifiy unique rows you can try this as well:

    WITH qry AS
    (
        SELECT a.* ,
            ROW_NUMBER() OVER(PARTITION BY id ORDER BY  Flag DESC ) rn
            FROM Table a
        WHERE ID = 7  -- THIS CAN BE PARAMETERIZED
    )
    SELECT * 
        FROM qry
    WHERE rn = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two queries that I want to be able to run on a
I have two queries that I run in the same table: SELECT id, COUNT(up)
I have two queries here. First one shows listings where a cat link =
I have two queries that are basically the same: OLD TRANSACTIONS QUERY SELECT t.payment_method,
I have two queries. The first query looks like this : SELECT subject_id, period,
I have two queries. The first query: select in_gentime from in_time_temp where cardnumber =
I have a query to select from another sub-query select. While the two queries
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
i have two queries, querying the same table, but based on different parameters, i
I have two queries that produce the same output. One is using the Intersect

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.