Sql - 从表中选择行,其中列值在另一个表中作为列名匹配 [英] Sql - select rows from table where column values matched as column name in another table

查看:705
本文介绍了Sql - 从表中选择行,其中列值在另一个表中作为列名匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 table-A 中选择行,其中类别列值匹配为表B中任何一个列名



I want to select rows from table-A where Category-column values matched as any one of the Column name in table-B

Table A	
	
UserName	Category
	
Raja	      ECE
Manoj	      CAT
Siva	      ENG
Kumar	      MAT
Viru	      WEB







Table B				
				
Name	ECE	MAT	ROB	ENG
				
Ching	10	0	7	9
Leeng	21	2	21	2







Need Output like :		
		
	UserName	Category
		
	Raja	       ECE
	Siva	       ENG
	Kumar	       MAT





我尝试过:



在从谷歌搜索SQL查询时,我无法获得正确的解决方案



What I have tried:

While searching SQL query from google, I cant get proper solution

推荐答案

select * from tablea where category in ( select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'tableb')


这篇关于Sql - 从表中选择行,其中列值在另一个表中作为列名匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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