Join (SQL) - Merge Rows

Merge Rows

To be able to do a select so as to merge multiple rows into 1 row : "group_concat notation".

MySQL and CUBRID use the group_concat keyword to achieve that goal, and PostgreSQL 9.0 has the string_agg function. Versions before 9.0 required the use of something like

array_to_string(array_agg(value),', ')

or the creation of an aggregate function.

Using the Employee Table:
LastName DepartmentID
Rafferty 31
Jones 33
Steinberg 33
Robinson 34
Smith 34
John NULL
to achieve the following results Table
DepartmentID LastNames
NULL John
31 Rafferty
33 Jones, Steinberg
34 Robinson, Smith


Read more about this topic:  Join (SQL)

Famous quotes containing the words merge and/or rows:

    Traditionally in American society, men have been trained for both competition and teamwork through sports, while women have been reared to merge their welfare with that of the family, with fewer opportunities for either independence or other team identifications, and fewer challenges to direct competition. In effect, women have been circumscribed within that unit where the benefit of one is most easily believed to be the benefit of all.
    Mary Catherine Bateson (b. 1939)

    Creatures that hang themselves up like an old rag, to sleep;
    And disgustingly upside down.
    Hanging upside down like rows of disgusting old rags
    And grinning in their sleep.
    Bats!
    —D.H. (David Herbert)