简体   繁体   English

带有concat的mysql select列

[英]Mysql select column with concat

i want some correction here. 我想在这里进行一些更正。 i want to select all people with name fred in database 我想选择数据库中名字为fred的所有人

Here's my query: 这是我的查询:

SELECT * FROM tdble WHERE CONCAT(name) LIKE CONCAT('%', REPLACE('fred', '')'%')

What you are asking can be simply achieved by either using the "=" operator of the wildcard operator "like" statement. 您可以通过使用通配符“ like”语句的“ =”操作符来简单地实现您的要求。

If you wish to find all records that have an exact match to the name 'Fred' then you should model your query as so: 如果要查找与名称“ Fred”完全匹配的所有记录,则应按以下方式对查询进行建模:

Select * From tdble Where Name = 'fred'

However, if you want to get all results where the names have 'fred' included in it somewhere use the wildcard operator. 但是,如果要获得名称中包含“ fred”的所有结果,请使用通配符。

Select * From tdble Where Name like '%fred%'

Also you can further model your query to know where exactly in which form you want 'fred' to appear. 您还可以进一步对查询建模,以了解您希望“ fred”以哪种形式确切显示。 Example if you want 'Fred' to be as the last characters of your name string, for instance you wish to get names which ends with fred then model your query like this: 例如,如果您希望“ Fred”作为名称字符串的最后一个字符,例如,您希望获取以fred结尾的名称,则可以对查询进行如下建模:

Select * From tdble Where Name like '%fred'

(you will get results like 'alfred', provided there is an alfred in your table) (如果表中有alfred,您将获得类似“ alfred”的结果)

However if you wish to get all names that begin with fred, model the query like this: 但是,如果您希望获得所有以fred开头的名称,请对查询进行如下建模:

Select * From tdble Where Name like 'fred%'

(you will get results like 'fredinane', provided there is a fredinane in your table) (如果您的表格中有fredinane,您将获得类似于“ fredinane”的结果)

Cheers 干杯

  • If you want to fetch record with name 'fred', you can simply do Select * from TableName Where Name = 'fred' . 如果要获取名称为'fred'的记录,则可以简单地Select * from TableName Where Name = 'fred'
  • If you want to fetch records which their names' string contain 'fred', you have to use select * from TableName where Name like '%fred%' 如果要获取其名称的字符串包含“ fred”的记录,则必须使用select * from TableName where Name like '%fred%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM