Apparently, it can also happen when you have two different queries in your SQL file, and you didn't separate them with a semicolon. I had this issue - it didn't recognize column names and marked my CTE name with a red line. The query itself worked perfectly fine but as soon as I added semicolon to the query above it the red lines went away.