Subject left join / first row select
Author

Hello,


I try to solve this problem already few days without success. 
I am using WI-V2.5.2.26540 Firebird 2.5 (windows 7).
I have two tables:
TABLE 1:

 

DATA_SUMMARY:
CON_ID_1 Data1
1 A
2 Bb
3 Dd
4 EE
1000 ABC


TABLE 2:


DATA_VIEW
CON_ID_2 Data2 Data3
1 D1 D1
1 D1 D1
2 D2 D2
2 D2 D2
2 D2 D2
3 D3 Z3
3 D3 Z3
4 D4 Z4
5 D5 Z5


As a results I would like to have 


Results:
CON_ID_1 Data1 CON_ID_2 Data2 Data3
1 A 1 D1 D1
2 Bb 2 D2 D2
3 Dd 3 D3 Z3
4 EE 4 D4 Z4
1000 ABC NULL NULL NULL


So idea is I combine TABLE 1 and TABLE 2 based on CON_ID_1 and CON_ID_2 but in table2 I can have few identical rows with the same CON_ID_2 value.


I tried to use such query


SELECT * FROM DATA_SUMMARY a

>left join
>(select first 1 * from DATA_VIEW) as c on c.CON_ID_2=a.CON_ID_1

unfortunetly it gives only NULL in the data_view tables part.


I cannot use DISTINCT(c.CON_ID_2) option because it take 2.5 min to sort complete table (both tables have few thousand  rows) 

On the internet I found only solutions for oracle and mysql but it doesn't for FB 


Any suggestions how to solve such problem?


Thanks for any feedback

Kukiejko