Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
Posted: Fri Sep 15, 2006 2:27 pm Post subject:
Try this:
Code:
select a.m_num,
b1.q_num,
b1.name,
b2.name as 'q_num name',
a.date,
a.wk as 'week'
from table_a a,
table_b b1,
table_b b2
where b1.m_num = a.m_num
and b2.m_num = b1.q_num
Thanks!.The query extracts data in an efficient way.
One more requirement to add to it.I have to combine another table which is l_table_b (late table-similar to table_b.The difference being the data loads into l_table_b in a week and where as data loads in table_b in daily basis)
Both table_b and l_table_b is similar in structure.Except the data stored in it is different.
I thought of using OR condition in where clause to the above.
the query looks like
Code:
select a.m_num,
b1.q_num,
b1.name,
b2.name as 'q_num name',
a.date,
a.wk as 'week'
from table_a a,
table_b b1,
table_b b2,
l_table_b b3,
l_table_b b4,
where b1.m_num = a.m_num
and b2.m_num = b1.q_num
or b3.m_num = a.m_num
or b4.m_num = b3.q_num
Not sure abt the query written above.
Can anyone help me to acheive a better result/query.
Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
Posted: Tue Sep 19, 2006 1:47 pm Post subject:
I would run a UNION:
Code:
select a.m_num,
b1.q_num,
b1.name,
b2.name as 'q_num name',
a.date,
a.wk as 'week'
from table_a a,
table_b b1,
table_b b2
where b1.m_num = a.m_num
and b2.m_num = b1.q_num
UNION
select a.m_num,
b1.q_num,
b1.name,
b2.name as 'q_num name',
a.date,
a.wk as 'week'
from table_a a,
l_table_b b1,
l_table_b b2,
where b1.m_num = a.m_num
and b2.m_num = b1.q_num
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum