SQL sorting case insensitive?

Ask here any questions regarding program functionality
RevSteve
Posts: 143
Joined: Thu Jun 28, 2018 5:45 am

SQL sorting case insensitive?

Post by RevSteve »

I found the command to sort alphabetically and it works well.

I was wondering about if it is possible to sort alphabetically with lower/upper case and give a command to sort and it would mix lower/upper together alphabetically?

That is, say a dictionary has some words...all lower case on first letter.
Then some words are capitalized first letter.

The only solution I have so far is before file becoming a database, change all subjects first letter to a capitol then use the command sql.

I tried to find that online but only found sketchy (to me) commands.
RubioTerra
Posts: 732
Joined: Wed Sep 23, 2009 5:13 pm
Location: Brasília, Brazil

Re: SQL sorting case insensitive?

Post by RubioTerra »

It depends on the database you're using, but it's something along these lines:

Code: Select all

select * from table sort by lower(sort_column);
Rúbio R. C. Terra
Brasília/DF - Brasil
RevSteve
Posts: 143
Joined: Thu Jun 28, 2018 5:45 am

Re: SQL sorting case insensitive?

Post by RevSteve »

Thanks Rubio, I'll play around with that sometime and see what happens.

I had decided a few days ago to just change all the subject topics first letter to capitols and then sort with the command I have.

I am not very good with SQL, only use it to make simple changes for the most part.

BTW, I saw this online, don't know if it can be used with what we do.

ORDER BY TITLE COLLATE NOCASE

My guess is this won't work...looks like it might mix stuff up we don't want it to;/
But maybe after some modifying...who knows?
RubioTerra
Posts: 732
Joined: Wed Sep 23, 2009 5:13 pm
Location: Brasília, Brazil

Re: SQL sorting case insensitive?

Post by RubioTerra »

Sorry, it's 'order by', not 'sort by'. But, trust me, one of these two is garanteed to work.

Code: Select all

select * from table order by lower(column); /* or... */
select * from table order by upper(column);
Rúbio R. C. Terra
Brasília/DF - Brasil
Post Reply