在SQL select语句中将多个列值合并为单个值

时间:2022-06-14 00:19:23

I have an autocomplete field where user can enter lastname firstname middlename in the same order.

我有一个自动填充字段,用户可以在同一顺序中输入lastname firstname middlename。

Using lastname firstname middlename (as a term) I have to show the autocomplete dropdown.

使用lastname firstname middlename(作为术语)我必须显示自动完成下拉列表。

On my database I have 3 columns for firstname lastname and middlename. Now I have to compare 3 column values (asc_lastname, asc_firstname, asc_middlename) of same row with user input (term).

在我的数据库中,我有3列firstname lastname和middlename。现在我必须将同一行的3个列值(asc_lastname,asc_firstname,asc_middlename)与用户输入(term)进行比较。

Here is the SQL query. Please correct my mistake.

这是SQL查询。请纠正我的错误。

$rs = mysql_query( "select asc_lastname, asc_firstname, asc_middlename from issio_asc_workers INNER JOIN issio_workers_asc_sc_list 
ON  issio_asc_workers.lname_fname_dob=issio_workers_asc_sc_list.lname_fname_dob where issio_workers_asc_sc_list.center_id='$cid' 
AND issio_workers_asc_sc_list.center_user_type = '31' AND issio_workers_asc_sc_list.center_status <> 'deleted' AND 
(issio_asc_workers.asc_lastname+' '+issio_asc_workers.asc_firstname+' '+issio_asc_workers.asc_middlename) 
LIKE '". mysql_real_escape_string($term) ."%'  ORDER BY issio_asc_workers.lname_fname_dob ASC LIMIT 0,10");

Is it possible to compare 3 column values at a time using a SQL query like

是否可以使用SQL查询一次比较3个列值

 select * 
 from table 
 where (column1+''+column2+''column3) like 'this is good'

Sorry for my poor sentences.

抱歉,我的判决很差。

1 个解决方案

#1


3  

Try this query:

试试这个查询:

SELECT * FROM your_table WHERE CONCAT(column1, ' ', column2, ' ', column3) LIKE '%this is good%'

Documentation for CONCAT

CONCAT的文档

#1


3  

Try this query:

试试这个查询:

SELECT * FROM your_table WHERE CONCAT(column1, ' ', column2, ' ', column3) LIKE '%this is good%'

Documentation for CONCAT

CONCAT的文档