'Select any field from any table
is it possible for a mysql statement to select any field from any table ?
for example :
SELECT * FROM * WHERE ? IN (SELECT * FROM *) to implement a generic search method which doesn't depends on a specific table or field. i've just read that we can list all tables of a database with a, SQL command : SHOW TABLES
Do you have any idea about how can we do this ?
Thank you :)
Solution 1:[1]
Create a procedure and use dynamic query mechanism e.g. below:
CREATE PROCEDURE dynamicQuery()
BEGIN
SET @tableName := 'TABLENAME1';
SET @SqlStr = 'SELECT * FROM @tableName';
PREPARE n_StrSQL FROM @SqlStr;
EXECUTE n_StrSQL;
DEALLOCATE PREPARE n_StrSQL;
END
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yogendra Singh |
