Duplicate Query assistance

B

Bender

I am trying to create a search form with a combobox and I want to the
populate combo box to be with the unique Budget codes but there are
many records with the same budget codes. I was hoping to create a
query on my "Projects" table to search for the duplicate "Budget
Codes" and only return one instance of a "Budget Code".

I am a novice when comes to SQL statements but, currently my query
looks like:

SELECT Projects.[Budget Subactivity]
FROM Projects
WHERE (((Projects.[Budget Subactivity]) In (SELECT [Budget
Subactivity] FROM [Projects] As Tmp GROUP BY [Budget Subactivity]
HAVING Count(*)>1 )));


Its returning:
2911
2911
2911
2912
2912
2912
2913
2913
2913
291X
291X

I would like the query to return:
2911
2912
2913
291X
without having to create a table of unique Budget Codes.

Does anyone have any tips / suggestions?
 
J

Jerry Whittle

You're working too hard!

SELECT DISTINCT [Budget Subactivity]
FROM Projects
WHERE [Budget Subactivity] Is Not Null
ORDER BY 1;

Please note that the Budget Subactivity is a text field and might not always
sort the way that you would like.
 
B

Bender

You're working too hard!

SELECT DISTINCT [Budget Subactivity]
FROM Projects
WHERE [Budget Subactivity] Is Not Null
ORDER BY 1;

Please note that the Budget Subactivity is a text field and might not always
sort the way that you would like.

--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.



Bender said:
I am trying to create a search form with a combobox and I want to the
populate combo box to be with the unique Budget codes but there are
many records with the same budget codes.  I was hoping to create a
query on my "Projects" table to search for the duplicate "Budget
Codes" and only return one instance of a "Budget Code".
I am a novice when comes to SQL statements but, currently my query
looks like:
SELECT Projects.[Budget Subactivity]
FROM Projects
WHERE (((Projects.[Budget Subactivity]) In (SELECT [Budget
Subactivity] FROM [Projects] As Tmp GROUP BY [Budget Subactivity]
HAVING Count(*)>1 )));
Its returning:
2911
2911
2911
2912
2912
2912
2913
2913
2913
291X
291X
I would like the query to return:
2911
2912
2913
291X
without having to create a table of unique Budget Codes.
Does anyone have any tips / suggestions?

Great thank you Jerry!
 

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


Top