Basically there are 3 things to be considered while investing. They are Safety, Liquidity and Returns.
If you are planning to buy a flat in next 3 years you will need to invest the money in hand in such a way that you can realise the money after 3 years without loss of value and if possible earn some returns. If you invest this in equity, in an adverse market situation, the value might go down by 10 to 15% in the 3 year period which you cannot afford. So it is better to invest the money in bank deposits.
Suppose you are retired and invested your money in bank deposit for 5 years at interest rate of 9%p.a. You have invested Rs.20 lacs and will monthly get Rs.15000 as interest. You need Rs.10000 now to meet your expenses. After 5 years the expenses might have gone upto Rs.13382 assuming inflation of 6%p.a. As economy is doing well the bank reduced interest rate and when you go to renew the deposit they say that the interest rate will be 7%p.a. There onwards you will get Rs.11667 per month only as interest. This is the risk with bank deposit. In this case you should be investing a portion of the money in equity.
If economy is doing well, then equity prices will go up and it will compensate for the reduced rate of interest. The focus should be on safety and liquidity for the short term and on return for the long term.
A financial plan will help you identify the right investments for you based on the time horizon of each goal, your risk tolerance and your current financial situation.