The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Return all results where category equals this or this or this, MS Access db on a classic asp page using strSQL
Pluribus
post Aug 6 2014, 08:48 AM
Post #1


Member
***

Group: Members
Posts: 81
Joined: 6-February 09
Member No.: 7,737



Hello

Can someone point me in the right direction to working out the correct string for this query?

I have a column in my database named "Category". I want to return all results from this column where the category equals 123, abc and xyz.

I can do it with one category, I have never managed to get 3 categories to work.

This is the connection string I use currently:

CODE
strSQL = "SELECT * FROM Table1 WHERE category=abc ORDER BY ID DESC"


Is this possible?

Regards

Ian
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Aug 6 2014, 10:30 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I think you just need to use AND, like this:
CODE
strSQL = "SELECT * FROM Table1 WHERE category=123 AND category=abc AND category=xyz ORDER BY ID DESC"
Also, you should try and use the same case as your database. In your post you state: 'column in my database named "Category"' but you use a lower case 'c' in your select statement. I 'assume' your column name for ID is upper case also?

Case might not matter but I have always followed my case rules and never had any problem.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Aug 10 2014, 02:02 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



>> I think you just need to use AND, like this:

OR might work better.
category = 'DOG' OR category = 'CAT'

will find where the category is *either* dog or cat. Using AND will only find cases where category is simultaneously cat and dog, and that will not happen much!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Aug 10 2014, 03:35 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I too wondered about that. The subject states 1 thing but I read the question as another. I thought the OP would correct me but he never replied.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Aug 10 2014, 05:09 AM
Post #5


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(Brian Chandler @ Aug 10 2014, 04:02 PM) *

>> I think you just need to use AND, like this:

OR might work better.
category = 'DOG' OR category = 'CAT'

will find where the category is *either* dog or cat. Using AND will only find cases where category is simultaneously cat and dog, and that will not happen much!


Normally we can say things like "Get the cats and dogs", meaning the union of the set of cats and the set of dogs; this is the same as the condition "X is a cat OR X is a dog". The AND combination will always return empty results, because nothing can be simultaneously a cat and a dog, so assuming the question is a real-world one, not an obscure academic quiz, the OR condition is likely to be the only helpful one.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 06:43 PM