简体   繁体   中英

Sort a list of words alphabetically and filter by first letter

I have this problem and I dont know where to start.
For example I have this in my database [this is just sample database ]

id  word
1   adore
2   and
3   apple
4   asore
5   banana
6   bate
7   beat
8   busy

How can I sort it and filter it so I only view words beginning with 'A'?

id  word
1   adore
2   and
3   apple
4   asore

You can use the SQL-LIKE-Statement.

SQL: SELECT DISTINCT word FROM Table WHERE word LIKE 'A%' This only returns words that start with an a.

This is lot simpler than you think. You can use SQL LIKE operator .

SELECT * FROM table WHERE word LIKE 'a%' ORDER BY word;
select id, word 
from your_table
where word like 'a%'
order by id 

or

select id, word 
from your_table
where substring(word, 1, 1) = 'a'
order by id 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM