by Hubert Chathi.
That's basically what IGNORE_MULTIPLE does.
By the way, don't use $CFG->prefix. Just wrap your table name in braces. ('SELECT * FROM {tablename} ...'). And don't user get_record_sql unless you really need to (get_records has both order and limit parameters).