SQL substring()匹配first-和lastname中的第一个字母

时间:2015-11-15 13:49:28

标签: mysql sql

我是SQL语言的初学者,我想知道如何匹配我的数据库中具有相同首字母的名称 名字和姓氏?

haskline

等等......

我的代码是:

For exemple:
Alex Andersen
Alice Aaronson
Brad Baalman
Brett Baren
Chris Cat

1 个答案:

答案 0 :(得分:1)

使用WHERE过滤记录:

SELECT *
FROM kids
WHERE LEFT(firstname, 1) = LEFT(lastname, 1)
ORDER BY firstname;

或:

SELECT *
FROM kids
WHERE SUBSTRING(firstname, 1, 1) = SUBSTRING(lastname, 1, 1)
ORDER BY firstname;
相关问题