MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old May 12th, 2005, 05:03 PM
xenzat xenzat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 3 xenzat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 19 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 13th, 2005, 08:01 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
You want to change the actual data in the table?
Or you want to change the results returned from a query?

Reply With Quote
  #3  
Old May 13th, 2005, 10:53 AM
xenzat xenzat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 3 xenzat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 19 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
You want to change the actual data in the table?
Or you want to change the results returned from a query?



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

Reply With Quote
  #4  
Old May 13th, 2005, 11:05 AM
xenzat xenzat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 3 xenzat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 19 sec
Reputation Power: 0
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

Reply With Quote
  #5  
Old May 15th, 2005, 09:17 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
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"


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Collapsing rows


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway