I've spent most of the day trying to research but still not able to find the answer. When trying to run the code below, I get an error message saying that "new_user_n ame" doesn't exist. The code below run correctly without the last filter (WHERE new_user_name = 'a'). Similar code work just fine using MySQL but I can't understand why SQL Server return an error message. Any thought on this?
Code:
SELECT id, first_name, (SELECT user_name FROM table2 WHERE table2.user_id = users.id) as new_user_name FROM users WHERE new_user_name = 'a'
Comment