David Milloway
David Milloway

Reputation: 21

How to collapse Similar Lines in SQL

Lets assume you have the following Data:

| COL 1 |  COl 2  | COL 3  |
| 10040 | [null]  | [null] |
| 10040 | [null]  |   Y    |
| 10040 |   Y     | [null] |
| 10070 | [null]  | [null] |
| 10070 |   Y     | [null] |

Is there any way using purely SQL to group by "COL 1" and collapse the data down to this:

| COL 1 |  COL 2  |  COL 3  |
| 10040 |    Y    |    Y    |
| 10070 |    Y    | [null]  |

Thanks in advance!

Upvotes: 2

Views: 113

Answers (1)

Hard Worker
Hard Worker

Reputation: 1121

I am not sure if this is what you need, but you can use many ways doing it such as:

There is no simplify then that:

select col1, max(col2), max(col3)
  from table 
 group by col1;

If you like, please comment and I will give you an example with an analytic function such as rank.

Upvotes: 3

Related Questions