sql for devices table