Query to Filter for Multiple Items

C

carl

My records look like this.

Record ID Code Count
1 ABC 2
2 EFG 5
3 HIJ 7
4 KLM 9
5 NOP 10
6 QRS 6

Is ther a way to query the data for a list of items ? For example, if my
list include is:

ABC
EFG
HIJ

Can a query return:

Record ID Code Count
1 ABC 2
2 EFG 5
3 HIJ 7


I need to do this on a large scale - the list would have around 2000 items
so doing it 1 at a time has been taking too long.

Thank you in advance.
 
O

Ofer Cohen

I'm not sure if that what you are looking for, but try this

Select * From TableName Where
Code:
 In ("ABC","EFG","HIJ")
 
C

Casey via AccessMonster.com

Dear Carl:

You can try this:
SELECT ID, Code, Count
FROM (tablename)
WHERE code IN ('ABC', 'EFG', 'HIJ');

Just change the part after the IN for any different queries on this.
Let me know if this helps!
 
J

John Spencer

Yes, there is a limit. I think you will run into a problem when you exceed 1024 characters.

A better way to handle this is to use a table to hold the list of items you want
and populate the table. Once you have the table populated you can join to the table.

SELECT ID, Code, Count
FROM [Name of your current table] INNER JOIN [Name of list items]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top