Using Microsoft SQL Server 2012.
I have a table called Loan with columns CustomerFname, CustomerLname, PropertyAddress, City, State, BankruptcyAttorneyName, UPB, and LoanDate.
For the sake of this question, I have to write a query to retrieve loan number, customer first name, customer last name, property address, and bankruptcy attorney name.
All of the records that have the same attorney name have to be together, then the customer last name in order from Z to A.
Here's the code I have so far:
SELECT LoanNumber,
CustomerFname,
CustomerLname,
PropertyAddress,
BankruptcyAttorneyName
FROM Loan
GROUP BY BankruptcyAttorneyName
ORDER BY CustomerLname DESC
Basically getting the error for all the columns not named BankruptcyAttorneyName.
invalid in select list because not contained in either agg function or GROUP BY clause.
I understand the error, but am unsure of how to go about it. I'm sure there's an easy way, but any help would be appreciated.
GROUP BYis always (almost) combined with aggregate functions, likeSUM,COUNTandMAX/MIN. I you don't need those, you probably don't needGROUP BYeither.