Query Master
Query Master

Reputation: 7097

Like keyword issue in MySQL

I want to display a result of ADSTech with the help of like Statement using ADS Technology keyword in MySQL like this

SELECT * FROM subcategories WHERE `name` LIKE '%ADS Technology%'

This result is required

enter image description here

Also see my database screenshot

enter image description here

Upvotes: 0

Views: 143

Answers (3)

Amit
Amit

Reputation: 13394

If I understood your question clearly, You can use any of the following query to get the results related to ADSTech or ADS Technology....

SELECT * FROM subcategories WHERE `name` LIKE '%ADSTech%' OR `name` LIKE '%ADS Technology%';

SELECT * FROM subcategories WHERE `name` IN ('ADSTech','ADS Technology');

Good Luck,

Upvotes: 1

user319198
user319198

Reputation:

It will not search because it's considering space.

you need to either remove space from keyword using before passing in query

$string_without_whitespaces = str_replace(' ', '', $string);

OR

$string_without_whitespaces = preg_replace('~\s~', '', $string);

OR split your keyword from space, like if using PHP use explode() and run your query around this array as per your needs.

$key=explode("",$keyword);

then

$query="SELECT * FROM subcategories WHERE `name` LIKE '%".$key[1]."%' OR '%".$key[2]."'";

OR

$query="SELECT * FROM subcategories WHERE `name` LIKE '%".$key[1].$key[2]."%'";

Upvotes: 2

Chetter Hummin
Chetter Hummin

Reputation: 6837

You could have a table which stores aliases for companies and then use that in the like as follows:

SELECT *
FROM subcategories sc, companyalias ca
WHERE ca.primaryname LIKE '%ADS Technology%'
  AND ca.name = sc.name

Upvotes: 0

Related Questions