Merged sql for datum