Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do you query multiple strings in MS Access

Posted on 2011-03-16
4
Medium Priority
?
346 Views
Last Modified: 2012-06-27
Hello,
I am querying multiple tables and I need to query for multiple strings e.g. "*zh" or "blaa*" or "frr*"

this is what I am curently using...

SELECT l_nbr, count(1) AS cnt
FROM (select * from 0219 where l_nbr  like "*zh"
UNION ALL
select * from 0220 where l_nbr  like "*zh"
) AS x
GROUP BY l_nbr;
0
Comment
Question by:groovymonkey
  • 3
4 Comments
 
LVL 18

Expert Comment

by:Cluskitt
ID: 35147653
SELECT l_nbr, count(1) AS cnt
FROM (select * from 0219 where l_nbr  like "*zh" or l_nbr like "*zh"
GROUP BY l_nbr
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 35147684
Nevermind, I misread wrong.

SELECT l_nbr, count(1) AS cnt
FROM 0219 INNER JOIN 0220 ON 0219.Id=0220.Id
WHERE 0219.l_nbr like "*zh" or 0220.l_nbr like "*zh" or 0219.l_nbr like "blaa*"
GROUP BY l_nbr

just keep joining tables and adding conditions.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35147687
try

SELECT l_nbr, count(1) AS cnt
FROM (select * from 0219 where l_nbr  like "*zh" or l_nbr  like "blaa*" or l_nbr  like "frr*"
UNION ALL
select * from 0220 where l_nbr  like "*zh" or l_nbr  like "blaa*" or l_nbr  like "frr*"
) AS x
GROUP BY l_nbr;
0
 
LVL 18

Accepted Solution

by:
Cluskitt earned 2000 total points
ID: 35147779
You can also try:

SELECT l_nbr, count(1) AS cnt
FROM (SELECT * FROM 0219
           UNION ALL
           SELECT * FROM 0220) AS x
WHERE l_nbr like "*zh" or l_nbr  like "blaa*" or l_nbr  like "frr*"
GROUP BY l_nbr
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question