Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

store in a @var a table's name from INFORMATION_SCHEMA.TABLES

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%smi%';
+--------------+
| TABLE_NAME   | 
+--------------+ 
| smiley_files | 
| smileys      |
| smiley_files |
etc.
But:
mysql> SELECT @name:=(SELECT(TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME ='smileys'));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual etc.

How can I capture a table’s name from INFORMATION_SCHEMA.TABLES and store in a @var (or into another table)?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

user define variables can only store one value so you would need somting like this

SELECT GROUP_CONCAT(TABLE_NAME) INTO @ltable 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_NAME ='smileys';

As Table you would use

  CREATE TABLE MY_table as
SELECT TABLE_NAME  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME ='smileys';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading