If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Getting Data Out

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-05, 12:28
nsarun nsarun is offline
Registered User
 
Join Date: Sep 2005
Posts: 1
Red face Getting Data Out

Hello Dear Folks,

It is hard to explain but let me see how well I can do it.

I have 3 tables A, B and C. A relates to B (1-to-many), B relates to C (1-to-0...more). But relating Ato C, for every row of A there will be 2 rows in C. Because of this relationship, I am not able to join all the three tables and get a single row. This results in 2 rows for each item. I would like the data from Table C as a result of the query to be side by side making it all one row. Like a horizontal join...


Here is the query

select ux.unit_slno, ux.catalog_no, ux.unit_status, ux.prepare_date, ux.prepared_by, mc.MAC_Addr, mc.sw_rev from unit_module_info ux, module_cfg mc, module_info mx where mx.unit_slno=ux.unit_slno AND mc.module_slno=mx.module_slno

in the two rows that results, sw_rev represents two different things.

Can you geniuses help me get a single row please?

Thanks
Arun

Last edited by nsarun; 09-27-05 at 13:44.
Reply With Quote
  #2 (permalink)  
Old 09-27-05, 17:47
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool


Post example data from all 3 tables.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 09-28-05, 08:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select ux.unit_slno
     , ux.catalog_no
     , ux.unit_status
     , ux.prepare_date
     , ux.prepared_by
     , mc.MAC_Addr
     , group_concat(mc.sw_rev) as sw_revs
  from unit_module_info ux
inner
  join module_info mx 
    on ux.unit_slno = mx.unit_slno 
left outer
  join module_cfg mc
    on mx.module_slno = mc.module_slno
group
    by ux.unit_slno
     , ux.catalog_no
     , ux.unit_status
     , ux.prepare_date
     , ux.prepared_by
     , mc.MAC_Addr
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 09-28-05 at 08:32.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On