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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:51:01+00:00 2026-05-26T00:51:01+00:00

First query This query works fine and the engine does not complain about it

  • 0

First query

This query works fine and the engine does not complain about it

SELECT id 
FROM agencies
WHERE id IN ((SELECT id FROM agencies))
ORDER BY id;

Second query

This one does not work, the engine is complaining about Subquery returns more than 1 row, when -according to me- I am doing the exact same thing when @param_1 IS NULL

SELECT 
  @param_1 := NULL,

SELECT id 
FROM agencies
WHERE id IN (CASE WHEN @param_1 IS NULL THEN (SELECT id FROM agencies) ELSE 1 END )
ORDER BY id;

Does anybody see why the engine is complaining about the second query when it isnt for the first query ?

Thanks in advance,

  • 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-26T00:51:01+00:00Added an answer on May 26, 2026 at 12:51 am

    CASE expects a scalar, single value. Not a record set.

    SELECT id 
    FROM agencies
    WHERE id IN (
            SELECT id FROM agencies WHERE @param_1 IS NULL
            UNION ALL
            SELECT 1 WHERE @param_1 IS NOT NULL
            )
    ORDER BY id;
    

    OR

    SELECT id 
    FROM agencies
    WHERE id IN (SELECT id FROM agencies)
         AND @param_1 IS NULL
    UNION ALL
    SELECT id 
    FROM agencies
    WHERE @param_1 IS NOT NULL AND id = 1
    ORDER BY id;
    

    Another choice is to use IF

    IF @param_1 IS NULL
        SELECT id 
        FROM agencies
        WHERE id IN (SELECT id FROM agencies)
        ORDER BY id;
    ELSE
        SELECT id 
        FROM agencies
        WHERE id = 1
        ORDER BY id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works fine: var q = (from c in db.tblLiteCategorySpecs where CategoryIDs.Contains(c.CategoryID) select c.SpecID).Distinct().ToList();
First, from BOL : Queries that modify table variables do not generate parallel query
I'm trying to parse HTML file with libxml2. Usually this works fine, but not
I want to do this query: SELECT * FROM mail WHERE tag_draft = 0
I have this elementary query: SELECT d.description, o.code FROM order_positions AS o LEFT JOIN
I have an MySQL query like this: SELECT MAX(messages.ID) as maxID, messages.from, messages.read, users.userName
this is my first question. I'm trying to execute a SQL query in django
I can't display the first entry from my query that returns multiple answers. For
I am using Entity Framework Code First. I want to query entites from database
I'm trying to make mod_rewrite the first sub-directory string from url in order to

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.