Faster query using joins