SQLTeam.com | Weblogs | Forums

X and Y data from 2 table queries


#1

Query1 returns a table (indep ) with values as the X value for plot
Query 2 returns a table ( depend ) with values for Y values of the plot

I'd like to do a select to inner join indep and with depend on certain criteria in order to end up with the
XValue on same row as YValue in order to plot.

Suggestions ?


#2

Can you supply table definitions, sample input/output?


#3

I think this would model what I need to do

declare @indep table (
RunID int ,
Xname varchar(10),
Xvalue int
)
insert into @indep (RunID,Xname,Xvalue)
values
(1, 'Sensor1',10),
(2,'Sensor1', 7);

declare @depend table (
RunID int ,
Yname varchar(10),
Yvalue int
)
insert into @depend (RunID,Yname,Yvalue)
values
(1, 'Sensor2',5),
(2,'Sensor2', 3);

with an output as
RunId Xname XValue YName YValue
1 Sensor1 10 Sensor2 5
2 Sensor1 7 sensor 2 3


#4

Try

SELECT I.RunID, I.Xname, I.Xvalue, D.Yname, D.Yvalue
FROM @indep I 
INNER JOIN @depend D ON I.RunID = D.RunID;

#5

Works great thanks !


#6

Glad I could help.