1

can I use the result of query (Query 1) as a table name into anothers query? Example. Query 1.

SELECT table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE' AND 
table_schema='schemaName' AND table_name LIKE '%_assoc_device'

I would like to use every single query just written, like table name, to build new queries.

SELECT * FROM (Query 1 Result)

This query for each result. With this automatic method, I would like to create a view

JoeJoe
  • 83
  • 1
  • 12
  • https://stackoverflow.com/a/3646442/6124528 – Manav Sep 20 '17 at 07:20
  • The solution is mySQL function? – JoeJoe Sep 20 '17 at 07:28
  • I Try to use this set of command, but must limit the result to 1 SET @sql := CONCAT('SELECT * FROM ', (SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='schemaName' AND table_name LIKE '%_assoc_device' LIMIT 1)); PREPARE s FROM @sql; EXECUTE s; DEALLOCATE PREPARE s; – JoeJoe Sep 20 '17 at 07:34

1 Answers1

0

I Try to use this set of command, but must limit the result to 1

SET @sql := CONCAT(
'SELECT * 
 FROM ', (SELECT table_name 
         FROM information_schema.tables 
         WHERE table_type='BASE TABLE' 
         AND table_schema='schemaName'
         AND table_name LIKE '%_assoc_device' LIMIT 1)
 );
 PREPARE s FROM @sql;
 EXECUTE s;
 DEALLOCATE PREPARE s;

Can I Extends this concept, to all result of subquery?

JoeJoe
  • 83
  • 1
  • 12