I wrote the internal equivalent of a subquery. Can someone tell me if this is the right way to do things, and if this is a more efficient way. Filters the ON keyword just like the where clause
Subquery
select
companyId,
fiscalYear,
fiscalQuarter,
periodenddate
into
from(
select
fp.companyId,
fp.fiscalYear,
fp.fiscalQuarter,
fi.periodenddate,
ROW_NUMBER() OVER (PARTITION BY fp.companyId, fp.fiscalYear, fp.fiscalQuarter ORDER BY fi.periodEndDate DESC) rowno
from ciqfinperiod fp
join ciqfininstance fi on fi.financialperiodid = fp.financialperiodid
where fp.periodtypeid = 4
and fi.periodenddate > @date
and fi.latestforfinancialperiodflag = 1
and latestfilingforinstanceflag = 1
and fp.companyId in (select id from
) a
where a.rowno = 1
internal connection
select
companyId,
fiscalYear,
fiscalQuarter,
periodenddate
into
from(
select
fp.companyId,
fp.fiscalYear,
fp.fiscalQuarter,
fi.periodenddate,
ROW_NUMBER() OVER (PARTITION BY fp.companyId, fp.fiscalYear, fp.fiscalQuarter ORDER BY fi.periodEndDate DESC) rowno
from ciqfinperiod fp inner join
join ciqfininstance fi on fi.financialperiodid = fp.financialperiodid
where fp.periodtypeid = 4
and fi.periodenddate > @date
and fi.latestforfinancialperiodflag = 1
and latestfilingforinstanceflag = 1
) a
where a.rowno = 1
source
share