I've large data which could be filtered on type column. I can get rows data using subquery with self-join and transform to the column, but due to large data, it would take a lot of time using a subquery. My table structure is like:
Table A
Id | ItemName | Type
1 | Item1 | A
2 | Item2 | A
3 | Item3 | B
4 | Item4 | B
Table B
Id | ItemDescTag | Ext
1 | ItemTag | A
4 | ItemTag | B
Query
Select ItemName,PurchaseOrdr.Quantity, PurchaseOrdr.PORate, PurchaseOrdr.CostAmount
from TableA its
left join (
select it.Id, it.Quantity,(it.CostAmount/it.Quantity)as PORate, it.CostAmount from TableA it
inner join Table B m on it.Type = convert(int ,m.Ext)
)as PurchaseOrdr on PurchaseOrdr.Id = its.Id
I need an alternate way to get rid of this SUB-QUERY because I have to make 10 SUB-QUERY of a similar type to get the required data and due to millions of records it slows down ...