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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:43:22+00:00 2026-06-17T06:43:22+00:00

I have a simple JPQL query. (But this applies also to an sql query..)

  • 0

I have a simple JPQL query. (But this applies also to an sql query..)

FROM DomainObj d where d.field1 like 'TEST%' and d.field2 like '%';

If the DB contains the following row:

1) field1 -> ‘TEST’; field2 -> null

the query return nothing!

If the DB contains the following values:

2) filed1 -> ‘TEST’; field2 -> ”

the query return the row!

How can I include also null values while searching for like ‘%’ keeping the query as simple as possible (avoiding and/or clause?)

I’m implementing searching funcionality of an entity in the db.. and I also search by many fields at the same time..

Thank you
Marco

  • 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-17T06:43:23+00:00Added an answer on June 17, 2026 at 6:43 am

    You can’t directly use nulls in equality tests, because null is un-equal to everything, including itself. That’s why there’s the is null test, e.g:

    select null = null -> null
    select null <> null -> null
    select 1 = null -> null
    select 1 <> null -> null
    select 1 + null -> null
    

    essentially null is contagious, and will nullify anything it’s compared to, or added in to.

    So yes, you’ll have to do

    SELECT ... WHERE somefield LIKE '%...%' or somefield IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple query, but when I'm trying to execute this query I'm getting
i have simple html5 video player like this <video id=video controls=true src=video.webm></video> If the
I have simple JSF application. Everything works fine, but not navigation. It behaves like
I have simple ASP.NET MVC action like this : public ActionResult Edit(EditPostViewModel data) {
I have simple models with generic relations from this example at the Django Project
I have simple view in my Ember.js application, like this. Each content element consists
I have simple scenario where I have AnotherTest value based on Test value. This
I have simple WCF Service Application (based on this tutorial : Getting Started ).
I have simple query which is taking around 7-8 seconds for to retreive the
I have simple data: [{label:Test 1,data:1332},{label:Test 2,data:56187},{label:Test 3,data:2},{label:Test 4,data:2},{label:Test 5,data:42946},{label:Test 6,data:1}] and when i

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.