Hi Harshil,
To my understanding, you are trying to build a query based on join to same table. I am bit not sure of the business scenario for framing the query this way and sure there can be a better alternative for this scenario.
How ever you can try the below example and please note that I have not tested this-
Query query = new Query();
QueryBuildDataSource queryOrderTable1;
QueryBuildDataSource queryOrderTable2;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
OrderTable locOrdTable;
queryOrderTable1 = query.addDataSource(tablenum(OrderTable));
queryOrderTable2 = queryOrderTable1.addDataSource(tablenum(OrderTable));
queryOrderTable2.addLink(fieldNum(OrderTable , Id), fieldNum(OrderTable , Id));
queryOrderTable2.addLink(fieldNum(OrderTable , ComponentId ), fieldNum(OrderTable , ComponentId ));
queryOrderTable2.joinmode(JoinMode::LeftJoin)
queryOrderTable2.fetchMode(QueryFetchMode::One2One);
queryOrderTable2.addRange(fieldnum(OrderTable,LineId )).value('0');
queryRun = new QueryRun(query); //queryrun will have the resultset
while(queryRun.next())
{
//play with the result set
locOrdTable = queryRun.get(tablenum(OrderTable));
}