devxlogo

Workaround for the SQL DISTINCT Clause

Workaround for the SQL DISTINCT Clause

The SQL DISTINCT clause isn’t case sensitive, which means that your query might end up pulling records with different cases.

A simple fix for this is to use the COLLATE clause in conjunction with the DISTINCT clause.

Use sql_latin1_general_cp1_ci_ai for case sensitive distinct clause:

a) CASE INSENSITIVE DISTINCT CLAUSESELECT DISTINCT (Item) COLLATE sql_latin1_general_cp1_cs_as    FROM (           SELECT  'a' item 	   UNION ALL SELECT  'A'	 )itemsb) CASE SENSITIVE DISTINCT CLAUSESELECT DISTINCT (Item) COLLATE sql_latin1_general_cp1_ci_ai    FROM (           SELECT  'a' item	   UNION ALL SELECT  'A'	 ) items

devx-admin

Share the Post: