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

Can DISTINCT be used on only one field in a query?

How do you do a DISTINCT on one field in the select clause and just include other fields in the select clause, not making them distinct?

For example:

 SELECT DISTINCT IndivOrders.DATE_INVC, IndivOrders.ID_ORD, IndivOrders.ID_SHIP, IndivOrders.ID_CUST_SOLDTO, IndivOrders.ID_PO_CUST, IndivOrders.TYPE_ORD_CP, IndivOrders.SEQ_SHIPTO, IndivOrders.ID_CUST_BILLTO, IndivOrders.NAME_ORD_BY INTO DistinctIndivOrders FROM IndivOrders
I just want Date_Invc to be distinct. I do not want the others to be distinct. If I use a group by, I get an error because the other information in the select clause is not in the aggregatte.

Not possible. You have to query out all of the distinct values in one query and then take these results and reuse them to pick up the additional data.

 

For More Information

This was last published in May 2002

Dig Deeper on Microsoft SQL Server Installation

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

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close