This query gets data, but for 116819 rows I need to wait 2:19 minutes. Getting the same data from the table takes 2-3 seconds, but I need some rows from the view (that are matching my data from table) in my query. How can I make it faster? The database that I work on is created properly.
select aa.*, b.quantity, b.price, case when b.itemNr is null then 'status' else 'status1' end as Status from( Select a.*, b.quantity, b.price, b.itemNr From table a left join view b on a.itemNR = b.itemNr and a.itemLine=b.itemLine) aa where aa.itemType = 'a type' group by .... order by ...
If I remove
group by and
order by, the query takes 2:10 minutes, so I reduce it only by 9 seconds.