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:

    We don’t know when our name came into being or how some distant ancestor acquired it. We don’t understand our name at all, we don’t know its history and yet we bear it with exalted fidelity, we merge with it, we like it, we are ridiculously proud of it as if we had thought it up ourselves in a moment of brilliant inspiration.
    Milan Kundera (b. 1929)

    Over the low, barnacled, elephant-colored rocks,
    Come the first tide-ripples, moving, almost without sound, toward
    me,
    Running along the narrow furrows of the shore, the rows of dead clam shells;
    Theodore Roethke (1908–1963)