What you are asking about is the formation of sandstone.
There is more to the process than just applying pressure; chemical changes, pressure, water and heat are all involved in the process.
When sand deposits accumulate they undergo a process called diagenesis, which involves,
physical and chemical changes in sediments first caused by water-rock interactions, microbial activity and compaction after their deposition. Increased pressure and temperature only start to play a role as sediments become buried much deeper in the Earth's crust.
During the process of diagenesis porosity of the sediment decreases.
The early stages of diagenesis can take place a depths of tens of meters.
As the sand undergoes additional compaction resulting from further accumulation of sand,
the sand comes under increasing pressure from overlying sediments. Sediment grains move into more compact arrangements, ductile grains (such as mica grains) are deformed, and pore space is reduced. In addition to this physical compaction, chemical compaction may take place via pressure solution. Points of contact between grains are under the greatest strain, and the strained mineral is more soluble than the rest of the grain. As a result, the contact points are dissolved away, allowing the grains to come into closer contact.
Mechanical compaction takes place primarily at depths less than 1,000 meters. Chemical compaction continues to depths of 2,000 meters, and most cementation takes place at depths of 2,000–5,000 meters.