COLLATE
COLLATE in SQL is a clause used to set the specific type of sorting order in a SQL statement. It determines the rules that SQL Server uses for sorting and comparison of data within a particular expression or column. The COLLATE clause can be used to customize a column's collation to meet specific needs. It controls the way in which data is sorted and compared based on the rules of the linguistic sort order defined by the collation.
Example
Output
NewColumnName |
---|
Data |
data |
DATA |
Explanation
In the COLLATE
clause, we have specified utf8_unicode_ci
as the collation, which makes the search case-insensitive. Thus, on executing the query, MySQL fetches the data in column1 transformed into a case-insensitive format under a new column called NewColumnName
.
Example
Output
Explanation
In this code snippet, ‘COLLATE “en_US”’ changes the sort order by collation of the ‘name’ column. The names are sorted using lexicographic order following the English language rules. For example, upper and lower case letters are considered to be equal.
Example:
Output:
Explanation
The COLLATE clause in SQL is used for defining the sorting order of specific columns, which can be helpful in dealing with strings from different languages and sets. In this specific example, the COLLATE clause is used for ordering Employee names in case-insensitive ascending order. SQL_Latin1_General_CP1_CI_AS is a Latin General, case-insensitive, accent-sensitive, kanatype-insensitive collation.
Example
Output
Explanation
The COLLATE
clause in Oracle allows you to specify the collation used for sorting the results. This SQL statement shows case-insensitive sorting using the BINARY_CI
collation, where ‘A’ and ‘a’ are considered the same for sorting purposes.