Adding link between three tables using Query class

Hi,

Hope you are doing well!

Kindly go through the below given SQL in order to understand my query

Select TabA
Where TabA.col1 == ‘xyz’
Join TabB
Where TabA.col1 == TabB.col1 &&
TabA.col2 != TabB.col2
join TabC
Where TabA.col1 == TabC.col1;

I did not find any way using addlink() method to achieve relation

TabA.col1 == TabB.col1 &&
TabA.col2 != TabB.col2

and

TabA.col1 == TabC.col1

I would appreciate any help you may offer.

Regards,

Abhinay

Edited:

the where clause for TabC is:

Where TabA.col3 == TabC.col3;

Example:

qbdsTabC = qbdsTabA.addDataSource(tableNum(TabC));
qbdsTabC.addLink(fieldNum(TabA, Col1), fieldNum(TabC, Col1));

You didn’t show your code, so I have no idea what you’re doing there. Ensure yourself that you link TabC to TabA and not to TabB.

Hi Martin,

The code is

qbdsTabB = qbdsTabA.addDataSource(tableNum(TabB));
qbdsTabB.relations(true);
qbdsTabB.addLink(fieldNum(TabA, Col1), fieldNum(TabB, Col1));
//(nocode for TabA.col2 != TabB.col2)

The moment I say

qbdsTabC = qbdsTabA.addDataSource(tableNum(TabC));
qbdsTabC.addLink(fieldNum(TabA, Col1), fieldNum(TabC, Col1));

the relation between TabA and TabB vanishes from qbdsTabA.

I don’t see anything wrong. I guess you’re verifying the result by QueryBuildDataSource.toString(), not by running the query. To see both child data sources there, you have to call fetchMode(QueryFetchMode::One2One) on both.