Very new to SQL Sever here... I understand the concept of joining tables, etc. but what is the easiest way to determine which columns are shared?
Say for instance we ha
Here is a handy query you can use to list out columns in a table:
SELECT c.name ColumnName
FROM sys.columns c INNER JOIN
sys.tables t ON c.object_id = t.object_id
WHERE t.name = 'something'
And here is a JOIN you could use to find common column names:
SELECT *
FROM (SELECT c.name ColumnName
FROM sys.columns c INNER JOIN
sys.tables t ON c.object_id = t.object_id
WHERE t.name = 'table1'
)t1
JOIN (SELECT c.name ColumnName
FROM sys.columns c INNER JOIN
sys.tables t ON c.object_id = t.object_id
WHERE t.name = 'table2'
)t2
ON t1.ColumnName = t2.ColumnName