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

  • Home
  • SEARCH
  • 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 9221263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:32:26+00:00 2026-06-18T03:32:26+00:00

simplified version of my query SELECT * FROM logs WHERE pw=’correct’ AND CASE WHEN

  • 0

simplified version of my query

SELECT *
FROM logs 
WHERE pw='correct' AND CASE WHEN id<800 THEN success=1 ELSE END 
AND YEAR(timestamp)=2011 

this doesn’t work. What i’m trying to do is to add in success=1 only for rows with id<800, else ignore this check.

how do i write this? thanks!

edit: to clarify, this what the table looks like

|id  | pw      | success |
--------------------------
|700 | correct | 1       |
|710 | correct | 1       |
|900 | correct | NULL    |
|999 | correct | 0       |

I’m trying to return all the rows, the column pw cannot be ignored.

  • 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-18T03:32:27+00:00Added an answer on June 18, 2026 at 3:32 am

    You don’t have to use CASE…WHEN, you could use an OR condition, like this:

    WHERE
      pw='correct'
      AND (id>=800 OR success=1) 
      AND YEAR(timestamp)=2011
    

    this means that if id<800, success has to be 1 for the condition to be evaluated as true. Otherwise, it will be true anyway.

    It is less common, however you could still use CASE WHEN, like this:

    WHERE
      pw='correct'
      AND CASE WHEN id<800 THEN success=1 ELSE TRUE END 
      AND YEAR(timestamp)=2011
    

    this means: return success=1 (which can be TRUE or FALSE) in case id<800, or always return TRUE otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a query in MS Access. This is a simplified version: SELECT IIf([category]
I have a query that uses the IN clause. Here's a simplified version: SELECT
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
I want to run a mysql query to select all rows from a table
Simplified version of the problem: So I have this query which is inside a
This is a simplified version of a query we are running where we need
I've pasted a very simplified version of my SQL query below. The problem that
I am debugging some code and have encountered the following SQL query (simplified version):
This is a simplified version of a query I have. Say for each customer
A simplified version of problem I am experiencing: Here is my HTML form: <form

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.