Link to home
Start Free TrialLog in
Avatar of checkmofoshoduno
checkmofoshoduno

asked on

How can i rewrite the following SQL statement?

How can i rewrite the WHERE clause with out using the use of IN special operator:
WHERE L_ST IN (‘WA’, ‘ID’, ‘NY’)
Avatar of mayank_joshi
mayank_joshi
Flag of India image

WHERE L_ST =‘WA’ or L_ST= ‘ID’ or  L_ST='NY’
Avatar of raulggonzalez
raulggonzalez

You can use OR like mayank_joshi said, but if I was you, I'd leave the IN ( ) ...

It's easier to read and will not mess with any other condition you may add ( you will need to use parenthesis or similar.)  


Cheers
ASKER CERTIFIED SOLUTION
Avatar of anushahanna
anushahanna
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lowfatspread

@anushahanna
   union all  probably

 


What are you actually asking us...
why do you need to re-write the statement...

as with most sql comparisons if the set of data is going to be repeatedly used then it should
 be set up on a table and reference (via a Join) that way....

create table State_groups (collection_name char(10) not null, grouping_name char(10) not null,
       State_alias cjar(2) not null, primary key (collection_name,grouping_name,state_alias))

e.g.  'UPSPOSTRATE','MIDWEST','WA'
           ....


from Yourtable as x
 inner join state_groups as s
  on x.l_st- s.state_alias
 and s.collection_name='UPSPOSTRATE'
 and s.grouping_name='MIDWEST'