dan
dan

Reputation: 9

mysql - select concat query

I'm trying to list all users beginning with a letter, e.g. D

Would the following be the right method of doing this.

Select concat(firstname, '',lastname) from users where concat(lastname) = "D*"

Upvotes: 0

Views: 2134

Answers (3)

Abin Kuruvilla Chacko
Abin Kuruvilla Chacko

Reputation: 14

For getting list starting with eg: "D":

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

Upvotes: -1

Randy
Randy

Reputation: 16677

i would try:

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

Upvotes: 0

Jacob
Jacob

Reputation: 43209

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.

Upvotes: 4

Related Questions