简体   繁体   中英

mysql - select concat query

I'm trying to list all users beginning with a letter, eg D

Would the following be the right method of doing this.

Select concat(firstname, '',lastname) from users where concat(lastname) = "D*"
SELECT concat(firstname, '',lastname) FROM users WHERE lastname LIKE "D%"

If you want to use wildcards, you need the LIKE operator. Also, in your where clause you only have one column (lastname), so you don't need concat .

我会尝试:

select * from users where lastname like 'D%';

For getting list starting with eg: "D":

SELECT concat(firstname, '',lastname) FROM users WHERE LEFT((concat(firstname, '',lastname)),1)= 'D';

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