skip to Main Content

I have a column in a table where the value is only a letter. The column name is ‘place’. When selecting everything from the table grouped by ‘place’, the letter A and the Danish letter Å is placed together. Why is that?

The encoding for the table is utf8mb3_general_ci and header of the PHP script is set to utf8.

I have tried to change the header of the PHP to iso-8859-1 with no luck.

2

Answers


  1. you must set rhe colation of the table. this set set sort order

    CREATE TABLE my_table (
        l CHAR(1),
        c INT
    ) ENGINE=InnoDB DEFAULT  COLLATE=latin1_danish_ci;
    
    
    insert into my_table VALUES ( 'A' ,1 ), ( 'Å' , 1);
    
    
    select l,sum(c) from my_table group by l;
    

    result

    l   sum(c)
    A   1
    Å   1
    

    sample https://dbfiddle.uk/JVaOtG3W

    Login or Signup to reply.
  2. You may want switch to utf8mb4 charset and utf8mb4_bin collation for supporting international characters.

    ALTER DATABASE `<db name>` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;
    
    ALTER TABLE `<table>` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search