on-internet
← Community

How can I show only the first instance of an SQL count?

Stack Overflow ·

In SQL Server I have table myTable with fields patientID, orderID, and orderDesc. Patients can have multiple orders with different descriptions. How do I write a query to select that information, plus a total count of the orders each patient received? I want the patient’s count to only return the value in each patient’s first row, and either null or be blank for the rest of the fields: PID Count OID 123 3 235 123 null 456 123 null 678 456 1 123 How can I implement nullif without it being inefficient?

Comments

Sign in or sign up to comment and upvote.

No comments yet.