1

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

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

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).

Here is the SQL query. Please correct my mistake.

$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

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

Sorry for my poor sentences.

4
  • This is not a jQuery related question.. Commented Jun 29, 2012 at 22:21
  • oh I am sorry removed jquery. As i am using jquery autocomplete plugin I added jquery also. Commented Jun 29, 2012 at 22:27
  • What you are trying seems a bit odd. Give us a concrete example of what you type and what you expect Commented Jun 29, 2012 at 22:28
  • I did changes. Please take a look Commented Jun 29, 2012 at 22:35

1 Answer 1

3

Try this query:

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

Documentation for CONCAT

Sign up to request clarification or add additional context in comments.

1 Comment

Thnak you so much. Thanks for documentation link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.