SELECT id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname
FROM " . TABLE_CONTACT . "
WHERE
CONCAT(firstname,' ', lastname) LIKE '%$goTo%' OR
CONCAT(firstname,' ', middlename,' ', lastname) LIKE '%$goTo%' OR
nickname LIKE '%$goTo%'
ORDER BY fullname";
任何人都可以告诉我上述查询的目的是什么?我是mysql的新手,所以无法理解它。感谢
答案 0 :(得分:5)
它将按昵称或全名搜索联系人,或使用initial来搜索姓名。此外,它将按字母顺序返回它们。
答案 1 :(得分:3)
它将查询数据库并获取id
并从名字和姓氏字段创建一个全名CONCAT(lastname,', ',firstname)
,并单独返回lastname, firstname
来自联系人表TABLE_CONTACT
传递%$goTo%
的变量应匹配:
想象一下DB中的这条记录:
id firstname lastname middlaname nickname
5454 Ibrahim Faour Ali ifaour
1- CONCAT(firstname,' ', lastname)
= Ibrahim Faour
2- OR CONCAT(firstname,' ', middlename,' ', lastname)
= Ibrahim Ali Faour
3- nickname
= ifaour
他们按新创建的列fullname