DISTINCT problem with ORDER BY
In the dataview designer, I have a table T with 2 fields F1, F2. I want
to see only F1. I put F1 in the Fields tab and F2 in the Order tab and
in the Table tab I check DISTINCT. In the SQL tab, it generate a good
SQL expression.
SELECT DISTINCT T.F1
FROM T T
ORDER BY T.F2
But, when I preview the table, it generate a wrong SQL expression.
SELECT DISTINCT T.F1, T.F2
FROM T T
ORDER BY T.F2
Where is my problem ?
Thank you
to see only F1. I put F1 in the Fields tab and F2 in the Order tab and
in the Table tab I check DISTINCT. In the SQL tab, it generate a good
SQL expression.
SELECT DISTINCT T.F1
FROM T T
ORDER BY T.F2
But, when I preview the table, it generate a wrong SQL expression.
SELECT DISTINCT T.F1, T.F2
FROM T T
ORDER BY T.F2
Where is my problem ?
Thank you
This discussion has been closed.
Comments
has to also be in the SELECT clause. Since it isn't supported on all
databases, we had to add to the select clause behind the scenes to avoid
database engine errors. The actual SQL that is going to be sent to the
server is what you see when you hit Ctrl-click over a dataview.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
side effect.
In the daMagicSQL unit in the TdaMagicSQL.GetOrderByFields method, I put
this 2 lines in comment.
// if (lField = nil) then
// lField := AddMagicSelectField(lTable, lOrderByField);
it may cause other problems and we can't support the problems they cause.
However, if it works that is cool so it doesn't add the select field behind
the scenes. Just make sure this SQL is supported on other databases if you
try this on other projects using a different database:)
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com