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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:28:54+00:00 2026-06-11T22:28:54+00:00

Consider a table results (id, key, value) where key is the Primary key. Sample

  • 0

Consider a table

results (id, key, value) where key is the Primary key.

Sample data:

id | key      | value
-----------------------
abc| source-1 | 20
abc| source-2 | 30
abc| source-3 | 2 
abc| source-4 | 10
def| source-5 | 1 
ghi| source-6 | 25
jkl| source-5 | 13

I would like to return only those records which have a single entry for a given id. So output should be

id | key      | value
------------------------
def| source-5 | 1
ghi| source-6 | 25
jkl| source-5 | 13

Please advise.

  • 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-11T22:28:55+00:00Added an answer on June 11, 2026 at 10:28 pm

    One way is to use GROUP BY and HAVING to produce a derived table with the desired ids and then JOIN to it:

    select results.*
    from results
    join (
        select id
        from results
        group by id
        having count(*) = 1
    ) as dt on results.id = dt.id
    

    You could also use an IN if you don’t like derived tables:

    select *
    from results
    where id in (
        select id
        from results
        group by id
        having count(*) = 1
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a table or CTE structured like this: Name Num ---- ---- Abc 12
Consider this table on SQL Server wordID aliasID value =========================== 0 0 'cat' 1
please consider this table: PK_Id Number Year Month Value ------------------------------------------------------------------------- 1 1 2000 5
Consider the table of events below. The OrderID field is a foreign key to
How to get the sum of foreign key table as a value in the
Consider the following table structure with data - AdjusterID | CompanyID | FirstName |
Consider fetching data with SELECT * FROM table WHERE column1='XX' && column2='XX' Mysql will
My SQL Server 2008 database table has a XML field. I would like to
Consider a table products which has product details including its category. One product may
Consider a table with the following schema: id, location, starred There are many records

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.