I ran into a little error trying to select off of my table. I am sure it is an easy fix but I can’t seem to locate the problem. It seems that my error message is telling me that I am selecting off a column that does not exist, even though it does.
The code
SELECT TOP (20) id
FROM school b
WHERE b.state = school.state
AND b.id <> school.id
ORDER BY NEWID()
The table “school”

The error msg

What are you trying to achieve with this query?
In the WHERE clause you appear to think you are querying from two tables:
but your FROM clause only specifies a single table:
The error messages is telling you that
school.stateis an invalid identifier. This is in fact true, because you have aliased the SCHOOL table, so onlyb.stateis valid in the scope of the statement.I think you trying to identify the IDs of schools which are in the same state as other schools. In which case you need to join it to itself, something like this: