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

  • Home
  • SEARCH
  • 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 8870443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:43:56+00:00 2026-06-14T17:43:56+00:00

WITH DATA AS ( select ACCT_ID_1, ACCT_ID, ACCT_ID_2 … from two tables joined by

  • 0
WITH DATA
     AS ( select ACCT_ID_1,  ACCT_ID, ACCT_ID_2 ... from two tables joined by criteria ),
DATA1
     AS (SELECT D1.*
           FROM DATA D1
          WHERE ACCT_ID_1 = ACCT_ID AND ACCT_ID_1 = '101'),
DATA2
     AS (SELECT D2.*
           FROM DATA D2
          WHERE ACCT_ID_2 = ACCT_ID AND ACCT_ID_2 = '101')

I need to get data1 if there is data in data1 ( no data from data2 ) else I need to get from data2. Is it possible using SQL?

  • 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-14T17:43:57+00:00Added an answer on June 14, 2026 at 5:43 pm

    This is probably how I’d do it:

    WITH data1 AS (
      SELECT 1
      FROM dual
      WHERE 1=2 -- Set to 1 to reverse result
    )
    , data2 AS (
      SELECT 2
      FROM dual  
    )
    SELECT *
    FROM data1
    UNION ALL
    SELECT *
    FROM data2
    WHERE NOT EXISTS (
      SELECT 1
      FROM data1
    )
    

    Posted on SQLFiddle as an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I select data from several tables. Then i need to edit the data returned
I need to select data from 2 tables in my DB - comments and
I am trying to select data from two tables and insert it into another
I need to select data from one table and insert it into another table.
i'm trying the following MySQL query to fetch some data: SELECT m.*, t.* FROM
I've used this MySQL query to get data: SELECT DISTINCT A.*, B.username FROM posts
I try to select data from database table with many conditional clauses where my
I'm trying to group data from the following three tables to create a new
I have the following data SELECT T.FEED_TIME from GLRS.FEED_TYPE T 05:00:00 AM 06:00:00 AM
In the following sample data i need to select all records where ModelOut=ModelOut (all)

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.