mysql alphabetical order

前端 未结 8 1438
臣服心动
臣服心动 2021-02-04 05:34

i am trying to sort mysql data with alphabeticaly like

A | B | C | D

when i click on B this query runs

select name from user order by \

相关标签:
8条回答
  • 2021-02-04 06:05

    Wildcard Characters are used with like clause to sort records.

    if we want to search a string which is starts with B then code is like the following:

    select * from tablename where colname like 'B%' order by columnname ;

    if we want to search a string which is ends with B then code is like the following: select * from tablename where colname like '%B' order by columnname ;

    if we want to search a string which is contains B then code is like the following: select * from tablename where colname like '%B%' order by columnname ;

    if we want to search a string in which second character is B then code is like the following: select * from tablename where colname like '_B%' order by columnname ;

    if we want to search a string in which third character is B then code is like the following: select * from tablename where colname like '__B%' order by columnname ;

    note : one underscore for one character.

    0 讨论(0)
  • 2021-02-04 06:07

    i want to show records only starting with b

    select name from user where name LIKE 'b%';
    

    i am trying to sort MySQL data alphabeticaly

    select name from user ORDER BY name;
    

    i am trying to sort MySQL data in reverse alphabetic order

    select name from user ORDER BY name desc;
    
    0 讨论(0)
  • 2021-02-04 06:07

    If you want to restrict the rows that are returned by a query, you need to use a WHERE clause, rather than an ORDER BY clause. Try

    select name from user where name like 'b%'
    
    0 讨论(0)
  • 2021-02-04 06:10

    MySQL solution:

    select Name from Employee order by Name ;
    

    Order by will order the names from a to z.

    0 讨论(0)
  • 2021-02-04 06:18

    I try to sort data with query it working fine for me please try this:

    select name from user order by name asc 
    

    Also try below query for search record by alphabetically

    SELECT name  FROM `user` WHERE `name` LIKE 'b%' 
    
    0 讨论(0)
  • 2021-02-04 06:19

    You do not need to user where clause while ordering the data alphabetically. here is my code

    SELECT * FROM tbl_name ORDER BY field_name
    

    that's it. It return the data in alphabetical order ie; From A to Z. :)

    0 讨论(0)
提交回复
热议问题