Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL ignore case in group by? (oracle)

Can you ignore case in a group by? For example if there is a table of states but it has records with "Alabama" and "alabama", or "Alaska" and "alaska" and you want the group by that column but just get back a single 'group' for Alabama and Alaska.

thanks

like image 781
llcf Avatar asked Nov 12 '10 18:11

llcf


People also ask

How do you write a case insensitive query in Oracle?

Starting with Oracle Database 10g Release 2 you can use the initialization parameters NLS_COMP and NLS_SORT to render all string comparisons case insensitive. We need to set the NLS_COMP parameter to LINGUISTIC, which will tell the database to use NLS_SORT for string comparisons.

How do you ignore a case in SQL?

Another way for case-insensitive matching is to use a different “collation”. The default collations used by SQL Server and MySQL do not distinguish between upper and lower case letters—they are case-insensitive by default. The logic of this query is perfectly reasonable but the execution plan is not: DB2.

Is GROUP BY case-sensitive?

If the User Locale is set to 'English', the GROUP BY in the SOQL behaves as case insensitive but for other user locales, it behaves as case sensitive. This is working as designed behavior when using current database. Via Anil on twitter.

How do I ignore a case in SQL Developer?

Select * from table where upper(table.name) like upper('IgNoreCaSe'); Alternatively, substitute lower for upper.


1 Answers

Just use UPPER:

select upper(state), count(1)
  from your_table
 group by upper(state);
like image 135
Pablo Santa Cruz Avatar answered Oct 16 '22 21:10

Pablo Santa Cruz