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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:21:37+00:00 2026-06-13T04:21:37+00:00

Here is a sample of the data I have: ———————————– ID | Item |

  • 0

Here is a sample of the data I have:

-----------------------------------
 ID | Item                 | Value
  1 | Carrot               |  0
  2 | Carrot               |  1
  3 | Peas                 |  1
  4 | Peas                 |  2
  5 | Peas                 |  3
  6 | Salad                |  0
  7 | Salad                |  3
  8 | Salad                |  5
  9 | Corn                 |  0
-----------------------------------

I want to do a query where the lines with values 0 appear if:

  • They are the only value for that item
  • There is more than one other value for that item

Or another way of saying is they should not be in the result if:

  • There is one and only one other value for the same item

Note that the pair (item, value) is unique in my data.

So for the data sample, the result of the query should be like this (only the first line goes away):

-----------------------------------
 ID | Item                 | Value
  2 | Carrot               |  1
  3 | Peas                 |  1
  4 | Peas                 |  2
  5 | Peas                 |  3
  6 | Salad                |  0
  7 | Salad                |  3
  8 | Salad                |  5
  9 | Corn                 |  0
-----------------------------------

What would be the best and most efficient way to do this?

  • 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-13T04:21:39+00:00Added an answer on June 13, 2026 at 4:21 am

    You will have to group the data by Item, so one possibility is

    SELECT ID, Item, Value 
    FROM data 
    WHERE Value <> 0
    OR Item IN
      (SELECT Item FROM data
       GROUP BY Item
       HAVING COUNT(*) <> 2);
    

    See this SQLFiddle

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

Sidebar

Related Questions

Here is the sample data for test table I have [childId] [parentId] [present] 1
I have table named x Here is the sample data in table x Column1_
I have a txt file, here is some sample data: Id,PriceOne,Company,PriceTwo,PriceThree 11,15.3599997,Japan ltd,12.23,3.1777777 12,,Koyoto
I have some html stored in a table. here is some sample data &lt;p&gt;&lt;span
Here is sample data <table class=sparql border=1> <tr> <th>abstract</th></tr> <tr> <td> Cologne is Germany&#39;s
Data: Here is sample table(TableA) data ID StartTime EndTime 1 2012-03-22 06:00:00.000 2012-03-22 06:30:00.000
I wrote a symfony task to fill a database of sample data. Here's a
Here's a sample column of my data frame, RR is a header : RR
Here is the sample code, which produces interesting output: > gg<-data.frame(x=c(a,b),y=as.integer(c(1000,100000))) > gg x
I am trying to sample a subset from data with replacement and here I

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.