Optimised sql queries to reduse database load