I have my MAIN table T1 from which I am doing select of many fields:
ID
1000
I have table T2:
ID SERVICE
1000 IPTV
1000 VOIP
I have table T3:
ID DEVICE
1000 MODEM
1000 ROUTER
1000 DVC
I want to JOIN T1 with T2 or T3 which can but also and might not have values at all !!!!
When they have values I want to have in SELECT number of records of maximum number of records from T2 or T3. So in this case T3 has 3 records which is maximum and I want 3 records in SELECT. (in case that T2 has 3 records that would be maximum in case that T3 has 2 records)
But in my SELECT statement I am having 5 records which I do not want. What is the correct expression for that? My below query returns 5 records (I want 3)
select t1.id,t2.service,t3.device
from t1
left outer join T2 on t1.id=t2.id
left outer join T3 on t1.id=t3.id
1 Answer