MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 21st, 2012, 04:21 AM
BismritI BismritI is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 BismritI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 53 sec
Reputation Power: 0
Join table

I have two table as per given below
Code:
 
+------+------------------+-----------+----------+------------+
| ssId | ssRegistrationID | ssSubject | ssScheme | ssSchemeId |
+------+------------------+-----------+----------+------------+
|    1 |           100000 |         2 |      256 | 1,2        |
|    2 |           100001 |         2 |      256 | 1,4,3      |
|    3 |           100002 |         2 |      256 | 2,4,3      |
|    4 |           100003 |         3 |      128 | 3          |
|    5 |           100004 |         2 |      256 | 1,3,4      |
+------+------------------+-----------+----------+------------+

Code:
 
mysql> select scId, scName from _scheme limit 4;
+------+---------------------------------------------+
| scId | scName                                      |
+------+---------------------------------------------+
|    1 | Open Category (HSTFS)                       |
|    2 | Dalit (HSTFS)                               |
|    3 | Indigenous Nationalities (Janajati) (HSTFS) |
|    4 | Daughter of BPKIHS Faculty/Staff (HSTFS)    |
+------+---------------------------------------------+

and I want above table given below

Code:
|    1 |           100000 |         2 |      256 | Open Category (HSTFS),Dalit (HSTFS)  


Please help me how to do this

Reply With Quote
  #2  
Old July 21st, 2012, 04:34 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
Do you have control over the structure of the tables?

If so, normalise.

Reply With Quote
  #3  
Old July 21st, 2012, 04:35 AM
BismritI BismritI is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 BismritI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 53 sec
Reputation Power: 0
How to do that ? I am beginner to MySQL
Quote:
Originally Posted by cafelatte
Do you have control over the structure of the tables?

If so, normalise.

Reply With Quote
  #4  
Old July 21st, 2012, 05:58 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 29 m 14 sec
Reputation Power: 4140
Quote:
Originally Posted by BismritI
How to do that ? I am beginner to MySQL
for background, search first normal form

what you need to do is remove the ssSchemeId column, because it violates first normal form

every column should be atomic, i.e. hold only one value

you need to create a relationship table to act as an intermediate table in between the ss table and the sc table

Code:
+------+------------+
| ssId | ssSchemeId |
+------+------------+
|    1 |    1       |
|    1 |    2       |
|    2 |    1       |
|    2 |    4       |
|    2 |    3       |
|    3 |    2       |
|    3 |    4       |
|    3 |    3       |
|    4 |    3       |
|    5 |    1       |
|    5 |    3       |
|    5 |    4       |
+------+------------+
so that where you had multiple values inside the single column, now there are multiple rows
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Join table

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap