Sql IN statement is always true

I have the following sql query

select * from tblArea where AreaDescription in ('Processing1','Geology 66','Site Infrastructure') 

he is currently showing records where AreaDescription is ('Processing1', 'Geology 66', 'Site Infrastructure')

but I need to pass the value to the query, which will always be true and show all the records. I know that I can use the where clause

 where 1=1 

but here i need to use the in.is instruction maybe?

+4
source share
3 answers

I don’t understand why you need it and why you don’t want to add where 1=1 or omit WHERE , but you can do it like this:

 select * from tblArea where AreaDescription in (AreaDescription,'Processing1','Geology 66','Site Infrastructure') 

Test: http://sqlfiddle.com/#!3/6e15d/1/0

+16
source

if you want your request to always be true ,

  • delete where clause
  • or add OR 1=1
+1
source

select * from tblArea where AreaDescription in (select AreaDescription from tblArea)

0
source

Source: https://habr.com/ru/post/1437945/


All Articles