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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:10:41+00:00 2026-05-27T18:10:41+00:00

I have a working solution, but I was wondering if there was a better

  • 0

I have a working solution, but I was wondering if there was a better way to get the same result.

The scenario:

User interface has a search filter that resolves to a GUID. So if they wanted to search for all records associated with customer John Doe, they would type in John Doe and before the final query is executed John Doe is resolved to John Doe’s customer_id. So if the customer_id is XYZ-456, the query would be:

SELECT id AS item_id FROM items WHERE items.customer_id = 'XYZ-456';

This would return the item ids which would then go through another process to provide the user with the full search results.

But obviously the user might not choose a filter at all. Rather than insert the entire WHERE parameter, I’ve gone with the following solution:

SELECT id AS item_id FROM items WHERE items.customer_id LIKE '%$customer_id%';

So if nothing is given, it resolves to:

SELECT id AS item_id FROM items WHERE items.customer_id LIKE '%%';

Which will return all items (the desired result).

Really, this works fine, but technically their is always the theoretical issue of the following customer_ids XYZ-456, EXYZ-4567, where the shorter of the two ids would return items for both customer_ids.

So is there a “right” way to say “return all results where field = ‘X’ but if ‘X’ is blank, return everything instead of nothing?”

  • 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-27T18:10:42+00:00Added an answer on May 27, 2026 at 6:10 pm
    where items.customer_id = '$customer_id' or '$customer_id' = ''
    

    logic like that also works well when filtering on multiple optional criteria.

    edit–a similar way

    where '$customer_id' in (items.customer_id, '')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a few developers working on the same VS2005 solution, but our source
i have this issue working but i would like to know if there is
There has to be a easy solution to this. I have been trying to
I have a working solution right now, but it seems really ugly for something
Hi I have been working on a solution for days, and I've been trying
I'm working in VS 2008 and have three projects in one solution. I'm debugging
Iam working on small booking room system. In my solution I have a Reservation
Wondering if there is any way to build and fire an event (e.g. on
I have a question about the best way to design a program I'm working
I'm having issues getting UpdatePanel working in a large, existing solution. I have a

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.