-1

Table A
Id name phone
1 sam   7753457893
2 tom   7753457893
3 pop   7753457893
4 john  7753457893

table B

name phone
sam   7753457893
tom   7753457893
pop   7753457893
john  7753457893

How to find if all the columns in table A are present in table B or not. I tried using except but I am getting a compilation error "invalid no of columns for set operator input branches, expected 22, got 11 ".I used this query "select * from table B except select * from table A". Table A has 22 columns and table B has 11 columns. I need a query to know that all the columns in table B are in table A

Basically I want to know table B is a subset of table A or not.

victor
  • 7
  • 2
  • Please provide sample data, desired results, and a database tag. – Gordon Linoff Jul 09 '18 at 18:29
  • Mostly you have to query on the information schema of your database. You have to provide more details about database.(ORACLE/MySQL/MSSQLServer). Also check this answer https://stackoverflow.com/questions/4849652/find-all-tables-containing-column-with-specified-name-ms-sql-server – Atul Jul 09 '18 at 20:36

1 Answers1

1

You can use this query SELECT ColumnFromB FROM TableB EXCEPT SELECT ColumnFromA FROM TableA This will give you a list of records that are in B but not in A. Then you can insert the result into a table variable, and check its COUNT (if count= 0 'subset' else is not subset).