I don't get results using 'WHERE' and 'AND'

Hello experts
I have a table Artextras
Artikel_ID     Extras
      253           10
      256           20
      264           20
      264          10
      264          40
      264          50
      264          60

And when i run the query:
SELECT *
FROM Artextras
WHERE Extras = 10
 AND Extras = 20
i don't get any results.I must get the Artikel_id 264 as result .where is the mistake?
LVL 2
PanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
you shoudln't be using AND...use OR

SELECT *
FROM Artextras
WHERE Extras IN (10, 20)
0
momi_sabagCommented:
you don't have a result since no rows have a extras=20 and extras=10
you want this

select t1.artikel_id
from Artextras t1 inner join Artextras t2 on t1.artikel_id = t2.artikel_id
where t1.Extras = 10
and t2.Extras = 20
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chapmandewCommented:
logically...AND would never work here on the same field.  One field can never have 2 specific values (for the same "cell")
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kevin CrossChief Technology OfficerCommented:
The answers above are correct --- this is an alternative to get what I think you are after.

You want to select id that has a record for 10 and for 20 and only those ids that do.

SELECT artikel_id
FROM Artextras a
WHERE extras = 10 AND EXISTS (SELECT 1 FROM Artextras b WHERE a.artikel_id = b.artikel_id AND extras = 20)

0
YZlatCommented:
SELECT *
FROM Artextras
WHERE Extras = 10 OR Extras = 20


0
YZlatCommented:
SELECT *
FROM Artextras
WHERE Extras = 10
 AND Extras = 20

will not return any results because no field Extras is both 10 and 20. You have to use OR:


SELECT *
FROM Artextras
WHERE Extras = 10 OR Extras = 20

this will return

 253           10
      256           20
      264           20
      264          10

0
PanosAuthor Commented:
Hi to all of you.
Thank you for your help.
looking at the question .....I must get the Artikel_id 264 as result .where is the mistake?......
i think that mwvisa1 and momi_sabag have found the way to get only 264 as result.
Now i will make a new question where these two numbers are not always the same but a variable.
Please help me with that too.
0
PanosAuthor Commented:
Thank you again for your help.
Regards
Panos
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.