且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在包含具有特定值的列的所有表中找到?

更新时间:2023-01-17 20:32:29

如果你不能列出表,我怀疑你可以在查询中做。您需要动态创建查询(使用您发现的表,如Paul Alan Taylor所示)。

If you can't list the tables, I doubt you can do it in a query. You'll need to dynamically create a query (using the tables you found like Paul Alan Taylor showed).

尝试调整:

http://ubercode.bleakllc.com/2008/11/find-any-value-in-any-database -column.html

如果您已经知道所有具有该列的表,并且该列表不会更改,则可以做一个简单的查询如

If you already know all the tables that have the column, and that list of tables isn't subject to change, then you can do a simple query like

  Select 'Table1' from table1 where id = 100
  UNION
  Select 'Table2' from table2 where id = 100
  UNION
  ...

将抛出所有的重复,所以如果多行有id 100,你只能得到表一次,如果这不是你想要的UNION ALL。

UNION will throw out all the dupes so if multiple rows have id 100, you only get the table listed once, if that's not what you want UNION ALL.