Support for table expression in DISTINCT

The DISTINCT function accepts also a table expression as an argument.