mysql : select ifnull(max(id),0) as maxid from table sqlserver : select isnull(max(id),0) as maxid from table