You do not want to simply suppress the message, as it is warning you that records are being overwritten in the array returned from get_records_sql() (in many cases, these will be records that have the same first field, but which may have differences in other fields).
There are a number of options you could use:
- $DB->get_recordset_sql() - this will return a recordset, rather than an array, you could then loop through the recordset to process the data
- Choose a field that will be unique for the first field returned (or, if you need to, use $DB->sql_concat(), to create a cross-DB CONCAT() statement that will generate a unique first field)
- Wrap your UNION in an outer statement that uses DISTINCT to remove the duplicates.