Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


What I have tried:

While searching SQL query from google, I cant get proper solution
Posted
Updated 17-Jul-17 18:29pm
Comments
Atlapure Ambrish 17-Jul-17 22:46pm    
Can you try this? I have not verified it, but it seems this is similar to your problem statement. https://forums.asp.net/t/1605429.aspx?SQL+Join+Tables+on+Column+Name+and+Row+Field+Value

1 solution

select * from tablea where category in ( select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'tableb')
 
Share this answer
 
Comments
SnvMohan 18-Jul-17 0:43am    
Thank you so much, Its working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900