selecting one and/or both

  • Thread starter Thread starter asc4john
  • Start date Start date
A

asc4john

Hi. I have a table column with entries like the following

TO-123
XO-234
TO-345
XO-345

I want to select TOs no matter what, XO only if there is no TO with a
matching number part.
and TO if there is a TO and XO with matching number part.
So I want from the above
TO-123, XO-234, and TO-345 (not XO-345)
 
Here is one way that works. Instead of three queries you could use subqueries.

selecting one count –
SELECT Right([xx],3) AS [Extract]
FROM [selecting one and or both]
GROUP BY Right([xx],3)
HAVING (((Count([selecting one and or both].xx))>1));

selecting one multi –
SELECT [selecting one and or both].xx, Right([xx],3) AS Expr1, [selecting
one count].Extract
FROM [selecting one and or both], [selecting one count]
WHERE (((Right([xx],3))=[selecting one count].[Extract]));

selecting one not multi –
SELECT [selecting one and or both].xx
FROM [selecting one and or both], [selecting one multi]
GROUP BY [selecting one and or both].xx, Right([selecting one and or
both].[xx],3), [selecting one multi].Extract
HAVING (((Right([selecting one and or both].[xx],3))<>[Extract])) OR
((([selecting one and or both].xx) Like "TO*"));
 

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

Similar Threads

query on date 1
grouping items based on last three digits 1
Retreive same record 4
Help Please 5
robocopy - XP kit 2
copying_data_using_FillHandle 1
Query 1
Crosstab query possibly? 2

Back
Top