HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Two rows having null values merge into one row without null values

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
rowswithoutmergenullintohavingtwoonevaluesrow

Problem

I have fetched the record from table like this:

Name                 Opp                     Bid                  Pro
----------------------------------------------------------------------
Admin                 2                      NULL                 NULL
Pragnya Sonal         7                      NULL                 NULL
Priyanka Debnath      17                     NULL                 NULL
Sanjeev Sasmal        2                      NULL                 NULL
Subrajeet Sahoo       1                      NULL                 NULL
Pragnya Sonal         NULL                   2                    NULL
Pragnya Sonal         NULL                   NULL                 1


But I want to reorder this table in this format:

Admin                 2                      NULL                 NULL
Pragnya Sonal         7                      2                    1
Priyanka Debnath      17                     NULL                 NULL
Sanjeev Sasmal        2                      NULL                 NULL
Subrajeet Sahoo       1                      NULL                 NULL


Can any one help me to solve this, thank you very much in advance

Solution

You can use grouping to get only one row per Name. If more than one row for the same Name and column have values you have to decide what to do with those values: do you want to see minimum, maximum, sum, average etc? So for example:

SELECT Name, min(Opp), min(Bid), min(Pro) FROM your_table GROUP BY Name

Code Snippets

SELECT Name, min(Opp), min(Bid), min(Pro) FROM your_table GROUP BY Name

Context

StackExchange Database Administrators Q#93628, answer score: 7

Revisions (0)

No revisions yet.