Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:29:29+00:00 2026-06-11T07:29:29+00:00

I have an complex situation. I want to write an sql query including case

  • 0

I have an complex situation. I want to write an sql query including “case when” condition on “where clause”.

Just like that:

SELECT *
FROM <table>
WHERE
<Column1> in
   CASE <Column2>
      WHEN 1 THEN ('OP', 'CL') 
      WHEN 0 THEN ('RE', 'ST')
END

Column1 must be “in”, not “=”. Because there is multiple value at condition for Column1. That query returns “Incorrect syntax near ‘,’.” error.

Can you give me any suggestion? (Sorry for my bad English.)

EDIT : I think I misunderstood. If Column2 is 1, condition must like that “IN (‘OP’, ‘CL’)” else Column1 is 2, condition must like that “IN (‘RE’, ‘ST’)”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:29:30+00:00Added an answer on June 11, 2026 at 7:29 am

    You don’t need a CASE expression for that, you can just use OR like this:

    SELECT *
    FROM <table>
    WHERE (Column2 = 1 AND Column1 IN ('OP', 'CL')) OR
        (Column2 = 0 AND Column1 IN ('RE', 'ST'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I have two arrays of objects. I want select
I have complex GUI application written in Python and wxPython. I want it to
We have a complex app that serves AJAX JSON streams (using ADO to grab
I have several complex data structures like Map< A, Set< B > > Set<
I have a complex RIA client that communicates with a WCF SOAP web service,
I have a complex MySQL problem. SELECT * FROM banners, content_id_country, languages WHERE content_id_country.content_id
I have a complex sorting problem with my SQL statement. I have a table
I have a fairly complex WordPress + bbPress installation and I would like to
So, here's the situation: I have a parent buildfile that defines a compilation task,
Here's the situation: i have a SearchPage where an user can make a complex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.