Creating getGID SQLQuery