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 319911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:42:17+00:00 2026-05-12T08:42:17+00:00

MySQL server version 5.0.45. Consider the following: ( SELECT CASE WHEN t.group_id = 12

  • 0

MySQL server version 5.0.45. Consider the following:

( SELECT CASE 
    WHEN t.group_id = 12 THEN 'yes' 
    ELSE 'no' 
    END
    FROM sample_table t
    WHERE t.user_id = 2
    AND t.group_id = 12 ) as foo

This subquery of a larger statement works as I’d expect, yielding a ‘yes’ or ‘no’ string value most of the time. It’s not ideal, but that’s what you get for working on someone else’s code!

However, sometimes the select can legitimately return an empty set, in which case foo is set to NULL. This does not actually break the application, but it’s irritating. Is there a way I can guarantee that foo will always be either ‘yes’ or ‘no’, even if there are no matching rows in the table?

  • 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-05-12T08:42:18+00:00Added an answer on May 12, 2026 at 8:42 am

    If it’s a scalar subquery, (i. e. you use in a SELECT or WHERE clause, not in FROM clause), then use this:

    IF(
    EXISTS
    (
    SELECT  NULL
    FROM    sample_table t
    WHERE   t.user_id = 2
            AND t.group_id = 12
    ), 'yes', 'no'
    )
    

    or even this:

    COALESCE(
    (
    SELECT  'yes'
    FROM    sample_table t
    WHERE   t.user_id = 2
            AND t.group_id = 12
    ), 'no')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 157k
  • Answers 157k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SyntaxHighlighter.all ties into the window.onload event - which only fires… May 12, 2026 at 11:07 am
  • Editorial Team
    Editorial Team added an answer Calling Builder::XmlMarkup.new without any indent parameter at all shouldn’t give… May 12, 2026 at 11:07 am
  • Editorial Team
    Editorial Team added an answer Try this rule: RewriteCond $0 !^frontend/ RewriteRule .* frontend/$0 [L] May 12, 2026 at 11:07 am

Related Questions

This MySQL script installs multiple triggers. It works on one machine running MySQL 5.0.51b-community.
We host a service (servlet running on jboss), which receives something like 5-6 requests
I have taken a dump from my mysql database on my own server (version
I'm having trouble with the MySQLdb module. db = MySQLdb.connect( host = 'localhost', user
I recently upgraded one of my applications to Rails 2.2.2. Having done that, I've

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.