Q
Problem solve Get help with specific problems with your technologies, process and projects.

Using DISTINCT on two fields

Can I use the function "distinct" on two fields? I need to retrieve from my database the number of accounts per month, but I don't want to add the accounts that are on the SAME day; same month is fine. Example:

 actNumber     date
 ?????????     ????
 222           10-jun-00
 222           10-jun-00
 222           11-jun-00
 222           12-jun-00
 333           12-jun-00
I want the count to be four. Can I put a distinct on two fields: account number and date?

Yes, you can put DISTINCT on two fields. So for your example, if you want the distinct account number and month, you might try a query as follows:

SELECT DISTINCT acctnbr,TO_CHAR(day,'MM') as month
FROM my_table;

For More Information


Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close