I'm learning SQL utilizing the common Microsoft AdventureWorks2014
sample database in SQL Server 2014
.
I just learned about HAVING
and Information Schema
today and am trying to combine the two.
Reason being, I'd really like to quickly tell which columns from all tables are shared. This works:
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
ORDER BY COLUMN_NAME, TABLE_SCHEMA
But... the output gives me unique column names that only slows me down.
I've tried applying answers from "How to select non 'unique' rows" (among 5-7 other SOF pages!) such as:
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
GROUP BY COLUMN_NAME
HAVING COUNT(COLUMN_NAME) > 1
...but I get this error:
Msg 8120, Level 16, State 1, Line 1 Column 'information_schema.columns.TABLE_SCHEMA' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.