Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

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?
Avatar of chapmandew
chapmandew
Flag of United States of America image

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

SELECT *
FROM Artextras
WHERE Extras IN (10, 20)
ASKER CERTIFIED SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
logically...AND would never work here on the same field.  One field can never have 2 specific values (for the same "cell")
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT *
FROM Artextras
WHERE Extras = 10 OR Extras = 20


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

Avatar of Panos

ASKER

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.
Avatar of Panos

ASKER

Thank you again for your help.
Regards
Panos