| Author |
Topic |
|
Mark Stilwell
Starting Member
6 Posts |
Posted - 2004-07-22 : 19:09:42
|
| Sorry people for a stupid question. Two tables are present.1. Equipment Table2. Equipment Component Table which links equipment to equipment (called COMP_NUM) Is there any way to write the following query without the nested select? In english the query is basically, "Get me the component number, component name, and master equipment number for all components of the master."SELECT EQ_COMPONENTS.COMP_NUM AS COMP, (SELECT EQUIPMENT."NAME" FROM EQUIPMENT WHERE EQUIP_NUM=COMP) AS COMPONENT_NAME, EQUIPMENT.EQUIP_NUM FROM DS2000.EQUIPMENT EQUIPMENT, DS2000.EQ_COMPONENTS EQ_COMPONENTS WHERE EQ_COMPONENTS.EQUIP_NUM='LH100-010'I Hope this makes sense and thanks in advance. |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2004-07-22 : 19:25:16
|
| Can you post the table designs, sample data and your required output?Makes things much easier.... |
 |
|
|
Mark Stilwell
Starting Member
6 Posts |
Posted - 2004-07-22 : 19:32:10
|
| Apologies...Equipment Table---------------Equip_NumDescription...Eq_Components Table-------------------Equip_NumComp_Num (Points back to the equipment table)Desired output is:Equip_Num, Comp_Num (Really from Equipment table), Comp_Description(Really from Equipment table)Sample output might look like this:'LH100-010','LH100-010a',"ComponentA"'LH100-010','LH100-010b',"ComponentB"'LH100-010','LH100-010c',"ComponentC"'LH100-010','LH100-010d',"ComponentD"I hope this helps and thanks! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-07-22 : 19:36:07
|
| Comp_Num relates to which column in the Equipment table? Comp_Description? I don't see that in the tables. You are looking for something like this though:SELECT t1.SomeColumn, t2.SomeOtherColumn, t1.SomeDiffColumnFROM Table1 t1INNER JOIN Table2 t2ON t1.Column1 = t2.Column1WHERE...Tara |
 |
|
|
Mark Stilwell
Starting Member
6 Posts |
Posted - 2004-07-22 : 19:41:41
|
| The desired output is:Equip_Num, Comp_Num (which IS Equip_Num), Comp_Description (which IS Equipment description) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-07-22 : 19:46:24
|
| You've shown us the desired output, but can you show us the data in the two tables that relates to the desired output.Tara |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-07-22 : 19:48:01
|
| BTW, it is considered bad design to have two columns named the same but contain different data. Equip_Num in the first table should be the same data as in the second table. If Comp_Num is how to connect to the first with Equip_Num, then they should be named the same.Tara |
 |
|
|
Mark Stilwell
Starting Member
6 Posts |
Posted - 2004-07-22 : 19:53:01
|
| Okay here we go given the desired output of'LH100-010','LH100-010a',"ComponentA"'LH100-010','LH100-010b',"ComponentB"'LH100-010','LH100-010c',"ComponentC"'LH100-010','LH100-010d',"ComponentD"The tables contain:Equipment Table---------------Equip_Num DescriptionLH100-010 MasterLH100-010a ComponentALH100-010b ComponentBLH100-010c ComponentCLH100-010d ComponentDEquipment Component Table-------------------------Equip_Num Comp_NumLH100-010 LH100-010aLH100-010 LH100-010bLH100-010 LH100-010cLH100-010 LH100-010dI hope this helps and thanks! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-07-22 : 19:55:50
|
| SELECT ec.Equip_Num, ec.Comp_Num, e.DescriptionFROM Eq_Components ecINNER JOIN Equipment eON ec.Comp_Num = e.Equip_NumTara |
 |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-07-22 : 21:43:34
|
I guess that's what I get for doing work at work!Like this:SELECTEQ_COMPONENTS.COMP_NUM AS COMP, EQUIPMENT.Name AS COMPONENT_NAMEEQUIPMENT.EQUIP_NUMFROM DS2000.EQUIPMENT EQUIPMENTINNER JOIN DS2000.EQ_COMPONENTS EQ_COMPONENTS ON EQ_COMPONENTS.COMP_NUM = EQUIPMENT.EQUIP_NUMWHERE EQ_COMPONENTS.EQUIP_NUM='LH100-010' <Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
|
|