0

How do I turn the following:

username | userLastFirst    | email             | approver1         |department
FAlbert  | Albert, Frankie  | abc123@ships.com  | Doe, John         |HR
FAlbert  | Albert, Frankie  | abc123@ships.com  | Smith, Mike       |HR

Into this:

username | userLastFirst    | email             | approver1    |approver2   |department
FAlbert  | Albert, Frankie  | abc123@ships.com  | Doe, John    |Smith, Mike |HR

Instead of multiple rows of the same user with their approvers, I'm looking to consolidate it into one record with columns of their approvers.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Vincent Luc
  • 1
  • 1
  • 3

1 Answers1

1

If you have two rows, you can use aggregation:

select username, userLastFirst, email, min(approver) as approver1 ,
       nullif(max(approver), min(approver)) as approver2, department
from t
group by username, userLastFirst, email, department;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • What if I have three approvers? – Vincent Luc Mar 04 '20 at 18:46
  • @VincentLuc . . . You would get two of them. If you wanted all three, you would have a different question -- your desired results here clearly have only two columns for approvers You should ask *new* questions as a *new* question. – Gordon Linoff Mar 04 '20 at 18:50