SQL to get apps installed in devices and apps in the store