Improve data feed, add unique sort column, select and having statements