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?
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 IndivOrdersI 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
- What do you think about this answer? E-mail us at editor@searchDatabase.com with your feedback.
- The Best Microsoft SQL Server Web Links: tips, tutorials, scripts, and more.
- The Best SQL Web Links
- Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL Server questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
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.