mysql - SQL: How to select values from multiple tables that contains specified column -


i want ask if know how values multiple tables have specified column.

for example have 5 tables (t1 ... t5) t2, t3, t4 contains column 'a' - how values of 'a' if don't know tables contains it?

i solution mysql (but postgresql).

thanks.

this should find columns on sql server. set column name in first commented area.

test test me area.

then use comments below switch printing query , executing query.

 declare @tab table (id int identity(1,1) primary key  ,table_catalog varchar(50)  ,table_schema varchar(50)  ,table_name varchar(50)  ,column_name varchar(50)) insert @tab(table_catalog ,         table_schema ,         table_name,         column_name) -------    test me select  table_catalog ,         table_schema ,         table_name,         column_name    information_schema.columns -- set column name looking for.   column_name = 'name' ---- order table_name ---- test me endline  declare @sql varchar(8000), @i int,@count int , @table_catalog varchar(50) ,@table_schema varchar(50) ,@table_name varchar(50)  ,@column_name varchar(50)   set @i=1 select @count= count(*) @tab while @i <= @count  begin select @table_catalog=table_catalog ,@table_schema=table_schema ,@table_name=table_name ,@column_name=column_name  @tab id=@i   set @sql = '   select '+@column_name+' column_name,*  ['+@table_catalog+'].['+@table_schema+'].['+@table_name+'] '  --to print sql queries screen  print @sql  -- uncomment , comment print above excute them. --exec (@sql)  set @i=@i+1 end 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -