|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Collapsing rows
I need to change a table that has information set up like this:
+---------+-------------------------+--------+--------+---------+-------+ | ID | Name | Type1 | Type2 | Type3 | Type4 | +---------+-------------------------+--------+--------+---------+-------+ | 10 | Gab | y | | | | | 11 | John | y | | | | | 12 | Vick | y | | | | | 12 | Vick | | y | | | | 13 | Nick | y | | | | | 13 | Nick | | | y | | +---------+-------------------------+--------+--------+---------+-------+ to a table that looks like this: +---------+-------------------------+--------+--------+---------+-------+ | ID | Name | Type1 | Type2 | Type3 | Type4 | +---------+-------------------------+--------+--------+---------+-------+ | 10 | Gab | y | | | | | 11 | John | y | | | | | 12 | Vick | y | y | | | | 13 | Nick | y | | y | | +---------+-------------------------+--------+--------+---------+-------+ I would like to do that with SQL... Is it doable? Thanks |
|
#2
|
||||
|
||||
|
You want to change the actual data in the table?
Or you want to change the results returned from a query? |
|
#3
|
|||
|
|||
|
Quote:
I want to combine the data from rows that have the same ID number. Sorry about the disposition of my table but here it is my challenge: I have to rows for the same person: I have a boolean value for type1 on one row and I have a second boolean value on a second row for type2. Before ID | Name | Type1 | Type2 | 01 | Tod | Y | | 01 | Tod | | Y | After ID | Name | Type1 | Type2 | 01 | Tod | Y | Y | This is what I need to do... Thanks |
|
#4
|
|||
|
|||
|
Heres a better example
I want to combine the data from rows that have the same ID number.
Sorry about the disposition of my table but here it is my challenge: I have to rows for the same person: I have a boolean value for type1 on one row and I have a second boolean value on a second row for type2. Before ID | Name | Type1 | Type2 | 01 |-Tod--|---Y---|-------| 01 |-Tod--|-------|---Y---| After ID | Name | Type1 | Type2 | 01|-Tod--|---Y---|---Y---| This is what I need to do... Thanks |
|
#5
|
|||
|
|||
|
Try
Code:
SELECT
ID,
Name,
IF(ID IN
(SELECT
ID
FROM
table
WHERE
Type1 = 'Y'),'Y',NULL) AS Type1,
IF(ID IN
(SELECT
ID
FROM
table
WHERE
Type2 = 'Y'),'Y',NULL) AS Type2
FROM
table
GROUP BY
ID
__________________
"A pawn is the most important piece on the chessboard -- to a pawn" |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Collapsing rows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|