0 votes
1 view
in SQL by (22.4k points)

I've been trying to figure out how I can make a query with MySQL that checks if the value (string $haystack ) in a certain column contains certain data (string $needle), like this:

mysql_query("

SELECT *

FROM `table`

WHERE `column`.contains('{$needle}')

");

In PHP, the function is called substr($haystack, $needle), so maybe:

WHERE substr(`column`, '{$needle}')=1

1 Answer

0 votes
by (40.3k points)
edited by

You can use this query:

Query:

mysql_query("SELECT *

FROM `table`

WHERE `column` LIKE '%{$needle}%' ");

Want to learn SQL from scratch? Here's is the right video for you on SQL provided by Intellipaat

Here, ‘ %’ is a wildcard that is used for any character.

Note: For very large datasets this can get slow. So, if your database grows then you need to use fulltext indices.

Related questions

0 votes
1 answer
0 votes
0 answers
asked Oct 7 in SQL by Tech4ever (22.4k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...