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
See also  Redefining Energy Management: Advanced Solutions for Modern Buildings

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist