How do I remove “duplicate” rows from a view?

后端 未结 5 1768
孤城傲影
孤城傲影 2021-01-06 10:58

I have a view which was working fine when I was joining my main table:

LEFT OUTER JOIN OFFICE ON CLIENT.CASE_OFFICE = OFFICE.TABLE_CODE.

5条回答
  •  太阳男子
    2021-01-06 11:14

    Instead of using DISTINCT, you could use a GROUP BY.

    • Group by all the fields that you want to be returned as unique values.
    • Use MIN/MAX/AVG or any other function to give you one result for fields that could return multiple values.

    Example:

    SELECT Office.Field1, Client.Field1, MIN(Office.Field1), MIN(Client.Field2)  
    FROM YourQuery  
    GROUP BY Office.Field1, Client.Field1
    

提交回复
热议问题