General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL 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:
  #1  
Old June 22nd, 2005, 04:44 PM
whiteherring whiteherring is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 2 whiteherring User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 0
joining multiple rows from a single table

There is a database table used to store financial analyltic information by source (vendor) and date. Rows in this table are sparsely populated, based on data availabilitiy from a given vendor.

Source. date...... a1.. a2. a3..
====== ======= === === ====
sourceA 20050621 12.3 40.2 546
sourceB 20050621 00.0 39.8 545


At run time, I recognize the preferred source for each of the analytic fields (columns), and want to create a query that returns a single result with column values from more than 1 row. For example, the I may want the result set to include the a1 value associated with sourceA and the a2 and a3 values associated with sourceB, so that the result set is as follows

12.3 39.8 234

How would I create a SQL query to fetch these values and return this result?

Reply With Quote
  #2  
Old June 23rd, 2005, 06:40 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
If you know exactly which cols you need from which rows, you can try:

Code:
SELECT
 t1.a1
,t2.a2
,t2.a3
FROM
 table AS t1
INNER JOIN
 table AS t2
ON
 t1.id = 'sourceA'
AND
 t2.id = 'sourceB'


This strikes me as a very messy way to do this, though -- depending on the specifics of your data and how you will determine which row's columns you need, there are probably more reliable ways.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
  #3  
Old June 28th, 2005, 08:59 PM
whiteherring whiteherring is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 2 whiteherring User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 0
Thanks for the information ... I was concerned there was no standard SQL method of performing the query, and now I realize I need to educate myslef a bit more on inner joins :-)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > joining multiple rows from a single table


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 6 hosted by Hostway