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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:02:48+00:00 2026-05-18T02:02:48+00:00

This is my table: id id_1 camp 1 0 x1 2 0 x2 3

  • 0

This is my table:

  id    id_1     camp 
 1        0         x1     
 2        0         x2
 3        0         x3
 4        1         x4
 5        1         x5
 6        1         x6
 7        3         x7
 8        3         x8
 9        3         x9 

I am in need of a SQL that, if there are no rows with id_1 of “x”, it should return those with id_1 of 0. For example, if I were to select id_1 = 2, it would return the select * whereid_1= 0.

Could this be done in one statement? I had little luck using IF EXISTS or CASE. Syntax…

Thanks, as always

  • 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-18T02:02:48+00:00Added an answer on May 18, 2026 at 2:02 am

    If there are no rows with id_1 of “x”, it should return those with id_1 of 0. You can try this –

    IF EXISTS ( SELECT * FROM mytable WHERE id_1 = 2 ) 
        SELECT * FROM mytable WHERE id_1 = 2 
    ELSE
        SELECT * FROM mytable WHERE id_1 = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables that look like this: Table 1 (main table): item_id (item_id,
I have large table (~1,000,000 rows) that may contain duplicates values. the table contain
I have a table that is basically set up so there is an id(UNIQUE),mapID,employe_ID,
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have something like this: create table account ( id int identity(1,1) primary key,
I have a couple of tables which look like this Table 1 user_id |
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
This is my table structure groupings id groupName 1 group1 2 group2 3 group3
I have this table. id name parents 1 Apparel 46 Apparel 1 47 Child

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.