Bhavna Bhavna - 9 months ago 37
SQL Question

Getting invalid object error when selecting data from SQL table

I have following data in my one of the table.

enter image description here

When I tried to execute following query

select * from t1 where c = ('US', 'UAE')

then I'm getting following error.

Msg 208, Level 16, State 1, Line 1 Invalid object name 't1'.

Answer Source

Part 1: From your error it seems that you are not able to access even table t1 because your error says

Invalid object name 't1'

An easy fix to get access to the table is, just connect to your database, open a NewQuery window and re-execute the query. I'm sure you will be able to access the table.

Part 2: Now if you see your query, then query itself is wrong. You need to use IN operator instead of = operator, because you want to filter out rows based on multiple values. So simply re-write your query as follows.

select * from t1 where c IN ('US', 'UAE')