Lai Yu-Hsuan
Lai Yu-Hsuan

Reputation: 28121

How does phpmyadmin implement "search" feature?

In phpMyAdmin, there is a search in database feature by which I can input a word and find it in any table(s).

How to implement it by SQL statement? I know the LIKE operation, but it's syntax is:

WHERE column_name LIKE pattern

How to search in all columns? Any how to specify it's a exact keyword or regular express?

Upvotes: 4

Views: 479

Answers (1)

jous
jous

Reputation: 845

SELECT * FROM your_table_name WHERE your_column_name LIKE 'search_box_text';

Where search_box_text is what you enter in the search. It will also say in the result page what kind of query it made. The same query with regular expressions is:

SELECT * FROM your_table_name WHERE your_column_name REGEXP 'search_box_text';

Remember that the wildcard in mysql is %. Eg. "LIKE '%partial_search_text%'

If you want to search in multiple columns, you can check which columns are in table with:

DESCRIBE TABLE your_table_name;

Or if you already know your columns:

SELECT * FROM your_table_name 
WHERE your_column_1 LIKE '%search%' 
OR your_column_2 LIKE '%search%'
OR your_column_3 LIKE '%search%';

Upvotes: 3

Related Questions