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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:55:34+00:00 2026-06-13T23:55:34+00:00

Pretty bad at MySQL as I’ve only done light web design and SQL on

  • 0

Pretty bad at MySQL as I’ve only done light web design and SQL on oracle dbs. Say I have a table listing all the fruits people like.

name   fruit
------------
john   bananas
john   oranges
marcy  bananas
dave   oranges
lucy   bananas
lucy   oranges

Say I wanted to get all the names of people that liked oranges but didn’t specify if they liked bananas. There’s only two possible fruits in this table. (It may expand to more but there are generally only two).

What would the query be? I want a query that only returns “dave” because marcy has only specified she likes bananas, and john and lucy say they like both. I don’t think I need a join since this is only one table.

I’m trying

select name from table
where(--uhm.. use the stuff below somehow
select name from table
where fruit like 'bananas';
select name from table
where fruit like 'oranges';
)

I would also be really happy with a query that returned all the people that like oranges but not bananas, or bananas but not oranges instead. I don’t know which query would be easier.

Also I’m sure I’d be able to find someone else with the same problem on the internet. What query would you use on google to answer my question?

  • 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-13T23:55:36+00:00Added an answer on June 13, 2026 at 11:55 pm

    I suppose this should do the trick:

    SELECT DISTINCT name 
      FROM fruits
     WHERE fruit = 'likedFruit'
       AND name NOT IN (
         SELECT name 
           FROM fruits
          WHERE fruit = 'hatedFruit');
    

    This query is better read from within:

    • first (with NOT IN nested query) you collect all the names of people not liking some specific fruit (let’s call them “fruit-haters”)
    • then, for each row you check both whether this row stores data about some good fruit AND, if so, whether the name attribute in this row is not the one of these pesky ‘fruit-haters’.

    We have to use either nested query or join here, as a single row doesn’t have all information about someone’s favorite fruits. And, actually, DISTINCT is not required in this particular case – but will be useful, if (name, fruit) combination is not UNIQUE.

    Here’s SQL Fiddle to play with. And here’s quite a helpful article comparing (performance-wise) several ways of achieving the same result.

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

Sidebar

Related Questions

Unfortunately I have a pretty bad understanding of how to properly set up threading.
I'm developing a WinForm application and I've done a pretty bad job thus far
I have a MYSQL Table with the following structure called daily_measurements +------------+----------+------+-----+---------------------+----------------+ | Field
Using mysql its pretty easy to get a page (lets say 20) of threads.
I have a MySQL table that represents a list of orders and a related
I am having a pretty bad night with this one. I have been running
I have a pretty large db in MySql, and I need to take backups
I am pretty bad at stating my problem clearly. Sorry. Basically, I have many
Ant seems to be pretty bad as running interactive program. So for instance, a
First of all sorry for my bad english and Im pretty new in these

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.