简体   繁体   English

如何在mysql中检查多个表

[英]How to check multiple tables in mysql

I'm doing a search my database called 'songs' and it got an average of 60 tables, all columns have the same name (id, name, data). 我正在搜索名为“ songs”的数据库,该数据库平均有60个表,所有列都具有相同的名称(id,名称,数据)。

SELECT * FROM (all tables in my DB songs) WHERE name LIKE 'a%';

How do I get the records that meet the condition "where" of all the tables? 如何获得满足所有表“ where”条件的记录?

You can use UNION 您可以使用UNION

  SELECT * FROM table1 WHERE name LIKE 'a%' 
  UNION 
  SELECT * FROM table2 WHERE name LIKE 'a%' ;

And on... 然后...

The question here is why do you have 60 same tables? 这里的问题是为什么您有60个相同的表?

Though UNION should be what you should go for but you can also do like below (an example) 尽管UNION应该是您应该追求的目标,但是您也可以像下面这样(示例)

select * from sample1,sample3,sample4 
where sample1.name like 'M%'
and sample3.name like 'M%'
and sample4.name like 'M%'

Moreover, if all 60 tables have same columns (as you mentioned) then what is the point in maintaining those many table? 而且,如果所有60个表都具有相同的列(如您所提到的),那么维护那些表的意义何在? Why not a single table? 为什么没有一张桌子?

To get all tables with columns 'id' or 'name' or 'data' in the database 'songs' 要获取数据库“歌曲”中所有具有“ id”,“ name”或“ data”列的表

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME
IN (
'id',  'name', 'data'
)
AND TABLE_SCHEMA =  'songs'

I can not think why there are 60 tables ? 我不认为为什么会有60张桌子?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM