Tags
MySQL
Asked 2 years ago
9 Jun 2021
Views 223
eclipse-learner

eclipse-learner posted

search query matching field name in MySQL

search query matching field name in MySQL
css-learner

css-learner
answered Apr 26 '23 00:00

To search for a specific field name in MySQL, you can use the INFORMATION_SCHEMA .COLUMNS table, which contains metadata about the columns in all databases and tables on your MySQL server.

Here's an example query that will search for all columns in the mytable table that match the name "myfield":


SELECT column_name
FROM information_schema.columns
WHERE table_name = 'mytable' AND column_name LIKE '%myfield%'

In this example, we are using the SELECT statement to retrieve the column_name column from the INFORMATION_SCHEMA .COLUMNS table. We then use the WHERE clause to filter the results to only include columns that belong to the mytable table and match the pattern "%myfield%" in their name. The % character is a wildcard that matches any sequence of characters.

This query will return a list of column names that match the specified search pattern
Post Answer