SQL to search across the database

0

Is there any command to do a select on all tables in a mysql database? Type I have multiple tables in my database with miscellaneous content. I need a way for a user to search for a keyword in all tables.

    
asked by anonymous 10.08.2017 / 19:29

3 answers

2

I made an example ... I created 3 totally different tables and put in each one 1 common content (my name, Walmir). Here's the data I've entered for example:

Foryoutoqueryinthese3distincttables,youcoulddothefollowing:

SELECT'tb_a'asref,a.nomeasresultFROMtb_aaWHEREa.nomeLIKE'%Walmir%'UNIONSELECT'tb_b'asref,b.descricaoasresultFROMtb_bbWHEREb.descricaoLIKE'%Walmir%'UNIONSELECT'tb_c'asref,c.conteudoasresultFROMtb_ccWHEREc.conteudoLIKE'%Walmir%'

Result:

Please see if it solves what you need. Anything leaves a comment that I modify this answer. Okay?

    
10.08.2017 / 20:45
1

The simple answer is: there is NO command to do this. You will have to implement multiple selects and join them, or create a script or stored procedure to achieve this, using the information_schema table.

It is important to be aware that this type of search can compromise your bank's performance.

If you have phpmyadmin installed you can use the search by selecting the database instead of the tables.

    
10.08.2017 / 20:55
0
SELECT * FROM information_schema.tables WHERE table_schema = 'bank-name';

removed from here

    
10.08.2017 / 20:21