The problem is that for each record mttablethere are probably several records sttable. Therefore, you do not need DISTINCT, but GROUP BY.
I would try something like the following for internal selection:
SELECT ROW_NUMBER() OVER(ORDER BY " + orderField + @") AS RowNum,
mt.ID AS mt_ID,
mt.title AS mt_title,
[...]
MAX(st.title) AS st_title,
[...]
FROM mttable AS mt
INNER JOIN sttable AS st on mt.ID =st.ID
WHERE st.field <> 0 AND mt.title = @title
GROUP BY mt.ID,
mt.title
source
share