新手在PostgreSQL中需要帮助

时间:2014-10-26 07:27:01

标签: postgresql

我当前的SQL语句是:

SELECT  *
FROM    names
WHERE   UPPER(first_name)                      LIKE UPPER('John Smith%')
OR      UPPER(last_name)                       LIKE UPPER('John Smith%')
OR      UPPER(first_name || ' ' || last_name)  LIKE UPPER('John Smith%')

我想在我的表中搜索“John Smith”,这个SQL语句没问题。 但是,如果我的名字为'John Kevin'且姓氏为'Smith',则不包括该条目。我需要添加什么?谢谢大家! :)

1 个答案:

答案 0 :(得分:0)

您可以使用“类似于”运算符来涵盖所有可能的组合。

Select * from table names UPPER(first_name || ' ' || last_name) 
SIMILAR to '%(UPPER(John)|UPPER(Smith))%';