1

I want to search in mysql database with columns containing some supplier names and it has values like. Bansbach GmbH (default) , Bansbach Feinmechanik and Bansbach xyzsomething. I need to get the result as an array where it contains results with columns containing exactly equal to Bansbach if not then check for both Bansbach and default. How to write a mysql query like this.

Now I've tried some thing like this.[only my where clause included here]

WHERE suppliername ='Bansbach'  

I need some thing like

 WHERE if(suppliername !='Bansbach' then (check it contains both bansbach and default)  

2 Answers 2

2

Plain regular SQL:

SELECT
  -- blah
FROM
  -- blah
WHERE
  suppliername = 'Bansbach'
  OR (
    suppliername LIKE '%Bansbach%'
    AND suppliername LIKE '%default%'
  )
;

EDIT

Why is this the same thing?

  • the OR branch will only ever be taken, if the first condition fails, this replaces you IF
  • "Containing both" is the same as "contain one AND contain the other"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. can I use NOT LIKE '%not use%'
0

Below sql should do a job for you:

SELECT
  suppliername
FROM
  [TABLE NAME]
WHERE
  suppliername = 'Bansbach' OR (suppliername LIKE '%Bansbach%' AND suppliername LIKE '%default%')

Comments

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.