【问题标题】:Search a column name in a few tables,not the whole database SQL在几个表中搜索列名,而不是整个数据库 SQL
【发布时间】:2015-04-01 22:17:35
【问题描述】:
SELECT something 
FROM table1, table2, table 
WHERE tableColumn = "tableName"

【问题讨论】:

  • 什么?您是否要求所有具有特定列名的表?您是否需要一个代码生成器来查找具有特定列名的所有表,然后对这些表进行查询?您是否要求连接其中 table1、table2 和 table3 在列中都具有相同的值?
  • "您是否要查询所有具有特定列名的表?"是的

标签: sql sql-server


【解决方案1】:

如果有必要,你可以对模式表做一些疯狂复杂的事情,但这应该在紧要关头起作用:

select <something> 
    from table1
    where 
        tableColumn = "tableName"
union all
select <something>
    from table2
    where 
        tableColumn = "tableName"
union all
select <something>
    from table3
    where
        tableColumn = "tableName"

只需确保从联合中的每个查询中选择相同类型的列即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 2015-10-29
    • 2021-07-25
    相关资源
    最近更新 更多