在多个表中搜索相同的值 [英] Search multiple tables for the same value

查看:57
本文介绍了在多个表中搜索相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有几个表的MYSQL数据库,所有表都具有相同的结构.我想搜索所有表以找到具有特定值的列的行.我必须一一搜索表格还是有一种更简单的方法?

I have a MYSQL database with a few tables, all of which have the same structure. I want to search all the tables to find a row with a specific value for a column. Do I have to search the tables one by one or there is an easier way?

推荐答案

您可以合并所有表.您仍然需要一张一张地遍历所有表,但是在union的情况下,您将不会进行笛卡尔乘法,因此从所有方面来看都是最好的:

You can union all tables. You still need traverse all tables one by one, but in case of union you will not have cartesian multiplication, hence best from all:

SELECT column FROM table1 WHERE column = 'value'
UNION ALL
SELECT column FROM table2 WHERE column = 'value'
;

这篇关于在多个表中搜索相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆