troubleshooting Question

A SQL question

Avatar of heyday2004
heyday2004 asked on
DatabasesOracle DatabaseSQL
16 Comments13 Solutions548 ViewsLast Modified:
This should be a typical SQL question:

Suppose I have a Product table with two columns: accountNum and name:

accountNum                name
1                                  Apple
2                                  Orange
2                                  Banana
3                                  Apple
4                                  Banana

Of course, the real table has much more data.

Now I want to get a list of accountNum where there is no name of Apple in the WHOLE table for this accountNum, I used below query:

select distinct accountNum from Product
where name not in
What I wanted to get is accountNum: 4. But sometimes,  I just got other accountNum, like 3, etc. It's obviously not working. Any explanation? Thanks.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 13 Answers and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 13 Answers and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros