1

I'm trying to select multiple values from 2 columns. I can get the query working with 1 column, eg:

SELECT *
FROM table
WHERE
    town IN ( 'Oxford' , 'Abingdon' )

However, I want to do something like:

SELECT *
FROM table
WHERE
    town IN ( 'Oxford' , 'Abingdon' )
AND type IN ( 'type1','type2')

but I can't get it to work.

Basically I want to select all where:

  • town=Oxford and type=type1

  • town=Oxford and type=type2

  • town=Abingdon and type=type1

  • town=Abingdon and type=type2

4
  • 2
    Second query looks good to me... unless I am totally missing something. Commented Aug 26, 2010 at 10:17
  • 2
    your something like query look that is good , did you try to run it? Commented Aug 26, 2010 at 10:18
  • "but I can't get it to work." - Do you get an error? Does it return no results? Is the data actually there for the scenarios you mention (i.e. are all Oxford and Abingdon records actually type3 and type 4)? Commented Aug 26, 2010 at 10:27
  • What exactly error do you receive? Commented Aug 26, 2010 at 10:27

1 Answer 1

1

Maybe this will work:

  SELECT * FROM table WHERE  (town IN ( 'Oxford' , 'Abingdon' )) AND (type IN ( 'type1','type2'))
Sign up to request clarification or add additional context in comments.

1 Comment

Well, It must be a bad day! I must have had a typo AND was stupid enough not to check the error messages before posting! You're all right - The query I typed into my message works - DOH!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.