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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:28:22+00:00 2026-06-14T00:28:22+00:00

I am wondering if it is possible in SQL to return a single row

  • 0

I am wondering if it is possible in SQL to return a single row to show, using the table below as an example, only a row for id 2:

table1  ( id 2 and 4 are missing value b)
id      value
1         a
1         b
1         c
1         d
2         a
2         c
2         d 
3         a
3         b
3         c
3         d
4         a
4         c
4         d

i basically want to find all instances where ‘b’ does not exist but ‘a’ still does exist for any id and return a single row for that any given id. i have tried something like this, but its not working as i would want it to:

select * from table1 
    where not exists (select distinct value from table1 where value b)   

i would like the end result to be something this, identifying the values where ‘b’ does not exist but ‘a’ does(not showing the value, is unneeded for final goal):

result table
id        
2           
4          
  • 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-14T00:28:24+00:00Added an answer on June 14, 2026 at 12:28 am

    This should do the job:

    select distinct id
    from table1 t
    where not exists (
        select 1 
        from table1 tt 
        where t.id = tt.id and tt.vallue = 'b'
    )  
    and exists (
        select 1
        from table1 tt 
        where t.id = tt.id and tt.vallue = 'a'
    )
    

    Below you have shorter form. It may perform better and distinct keyword may be unnecessary if the pair (id, value) is unique.

    select distinct id
    from table1 t
    left join table1 tt
    on t.id = tt.id and tt.value = 'b'
    where t.value = 'a' 
    and tt.id is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've using the basic Oracle SQL and I was just wondering if its possible
Possible Duplicate: SQL query to find Missing sequence numbers I have a table which
I was wondering if it is possible to add/update/delete an SQL Server database table,
You can return a single table from a T-SQL Function in SQL Server 2008.
I'm wondering is it possible to limit the result of a SQL request? For
I am wondering if it is possible to use an SQL function to name
I was wondering if it was possible to override column value in the Where
just wondering is it possible to use mixed mode on sql server 2005 for
Possible Duplicate: Change Notification with Sql Server 2008 Am just wondering is there's anyway
Possible Duplicate: Merge two rows in SQL I have the following values in table:

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.