Dev
Dev

Reputation: 6710

Query to make group of records

I have a table with data like below:

                 TableA
======================================
Name      colB       colM        colP 
======================================
T045      B          Null        Null
T045      Null       M           Null
T045      Null       Null        P
T046      Null       M           Null
T046      B          Null        Null
T047      Null       Null        P
T047      Null       M           Null
T048      B          Null        Null

I want a query to create results like below:

    ======================================
    Name      colB       colM        colP 
    ======================================
    T045      B          M           P
    T046      B          M           Null
    T047      Null       M           P
    T048      B          Null        Null

Does anyone have any ideas how do do this?

Thanks

Upvotes: 0

Views: 39

Answers (1)

podiluska
podiluska

Reputation: 51494

Yes. You need the GROUP BY syntax

select name, max(colb), max(colm), max(colp)
from table
group by name

Upvotes: 2

Related Questions