MS SQL Development
 
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 ForumsDatabasesMS SQL Development

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 February 6th, 2013, 11:09 AM
choppyfireballs choppyfireballs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 choppyfireballs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 24 sec
Reputation Power: 0
Merging two rows

Ok so I have two tables that I am joining in a join statement that works fine. I'm pulling the data that I want to pull just fine.

Quote:
SELECT table1.ID, table1.info1, table1.info2, table1.info3, table2.ExtraInfoName, table2.ExtraInfoValue
FROM table1 LEFT OUTER JOIN table2 ON Table1ID = ID


Let's say for this example let's say that I have table 1 with colums as such

ID |info1 |info2| info3
1 | a | b | c
2 | z | y | x

And I also have table 2 which has columns

ExtraID | ExtraInfoName(nvarchar) |ExtraInfoValue(nvarchar) |Table1ID
1 | name | david | 1
2 | age | 88 | 1
3 | name | steve | 2
4 | age | 9 | 2

So I get this as a result,

ID| info1| info2 | info3 | ExtraInfoName | ExtraInfoValue
1 | a | b | c | name | david
1 | a | b | c | age | 88
2 | z | y | x | name | steve
2 | z | y | x | age | 9

This is a problem for me because what I want to do with the data from this query cannot have duplicate ID but I need all the data from table2. So this is what I want it to look like.

ID | info1| info2| info3 | ExtraInfoName |ExtraInfoValue |ExtraInfoName| ExtraInfoValue
1 | a | b | c | name | david | age | 88
2 | z | y | x | name | steve | age | 9

Reply With Quote
  #2  
Old February 6th, 2013, 11:25 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,380 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 7 h 54 m 19 sec
Reputation Power: 4140
congratulations, you have just discovered one of the (many) drawbacks of the EAV (entity-attribute-value) anti-pattern

do the cosmetic re-arrangement of merging the rows in your application language

trying to do it with sql will bring only tears
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old February 6th, 2013, 12:08 PM
choppyfireballs choppyfireballs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 choppyfireballs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 24 sec
Reputation Power: 0
Quote:
Originally Posted by r937
congratulations, you have just discovered one of the (many) drawbacks of the EAV (entity-attribute-value) anti-pattern

do the cosmetic re-arrangement of merging the rows in your application language

trying to do it with sql will bring only tears


I had a feeling that this was going to be the case, thanks for confirming so quickly.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Merging two rows

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