0

I have a query like this :

$sql = "
        SELECT
            *
        FROM
            tbl_emp_data
        WHERE
            company_qualification = '$q'
    ";

Now my company_qualification field is not a single value ,instead its a words separated by commas like BSc,BA,BCom etc . And the value $q is a single value say BA . So how can I search the company data from the value $q . I can not use LIKE since its going to match fields like BA and BBA .

3 Answers 3

4

You can use FIND_IN_SET

$sql = "
        SELECT
            *
        FROM
            tbl_emp_data
        WHERE        
           FIND_IN_SET($q,company_qualification)
    ";
Sign up to request clarification or add additional context in comments.

2 Comments

SELECT * FROM tbl_emp_data WHERE FIND_IN_SET(B.A,company_qualification) LIMIT 0, 10
B.A is a string and must be surrounded by the single or double quote. put the '$q' in single quote and also make sure you are escaping user inputs before substituting them with query.
1
$sql = "
        SELECT
            *
        FROM
            tbl_emp_data
        WHERE
            company_qualification IN ('".implode("','",$q)."')
    ";

Comments

0

You can use IN like this:

SELECT * FROM tbl_emp_data WHERE company_qualification IN ('BSc', 'BA', 'BCom');

1 Comment

Ah, Shakti Singh got there first. I don't know the difference between IN and FIND_IN_SET though.

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.