I’m trying to get unique values in a single column while selecting multiple columns in SQL Server. Here’s what I’ve tried:
SELECT DISTINCT(OrderID), OrderDate, Description, TotalAmount, SupplierName,
OrderStatus, CustomerCharge, TaskType, LocationName, LocationID,
ReferenceCode, PaymentInfo, AccountNumber, TotalExpense
FROM OrderSummary
This didn’t work as expected. I also tried using GROUP BY:
SELECT OrderID, OrderDate, Description, TotalAmount, SupplierName,
OrderStatus, CustomerCharge, TaskType, LocationName, LocationID,
ReferenceCode, PaymentInfo, AccountNumber, TotalExpense
FROM OrderSummary
GROUP BY OrderID
But this requires using aggregate functions for other columns, which I want to avoid.
My actual query is more complex, involving JOINs and WHERE conditions. How can I get distinct values for just the OrderID column while selecting all other columns without using aggregate functions? Any help would be appreciated!