Pl. help [message #21298] |
Thu, 25 July 2002 05:03 |
New
Messages: 10 Registered: December 2000
|
Junior Member |
|
|
Can I get the result as i need from these two tables.
I have 2 tables like this
T1 has ser_id as auto number
T1
-------
ser_id ----- txt1 ----- txt2
1 --------- aaa ------ bbb
2 ---------- ccc ------ ddd
3 ---------- eee ------ fff
4 ---------- ggg ------ hhh
5 ---------- iii ------ jjj
T2 has MAIN_ID as auto number
and T2 may have one or more ser_id for each ser_id of T1
T2
-------
MAIN_ID ser_id
1 ----------- 1
2 ---------- 1
3 ---------- 2
4 ---------- 2
5 ---------- 2
6 ---------- 2
7 ---------- 3
8 ---------- 3
9 ---------- 4
10 ---------- 5
The output i need is for each ser_id in T1 to get MAIN_ID from T2
like
T1.ser_id T2.MAIN_ID T1.txt1 T2.txt2
-----------------------------------------------------
1 ------- 1 ------- aaa ------- bbb
2 ------- 3 ------- ccc ------- ddd
3 ------- 7 ------- eee ------- fff
4 ------- 9 ------- ggg ------- hhh
5 ------- 10 ------- iii ------- jjj
thanks in advance..
|
|
|
Re: Pl. help [message #21301 is a reply to message #21298] |
Thu, 25 July 2002 06:54 |
hi
Messages: 15 Registered: February 2002
|
Junior Member |
|
|
I am sorry if I donot understand your question
select t2.main_id,t1.ser_id,t1.txt,t2.txt from t1,t2
where t1.ser_id = t2.main_id
|
|
|
Re: Pl. help [message #21305 is a reply to message #21298] |
Thu, 25 July 2002 08:41 |
Kenzi Nego
Messages: 1 Registered: July 2002
|
Junior Member |
|
|
you may try the SQL below, as i don't have a db to try it out. pls correct me if it does not work.
select t1.ser_id, t3.min_main_id, t1.txt1, t1.txt2
from t1, (Select min(MAIN_ID) min_main_id, ser_id from t2 group by ser_id) t3
where t1.ser_id =t3.ser_id
|
|
|
|
|