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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:53:46+00:00 2026-05-24T17:53:46+00:00

I have this in info in a table where sometime the pd_id is NULL

  • 0

I have this in info in a table where sometime the pd_id is NULL

doc_id  doc_title   doc_order   pg_id 
14      a.zip       1           NULL    
15      b.zip       2           NULL    
12      c.zip       1           16  
13      d.zip       2           16      
3       f.doc       3           16      
4       g.doc       4           16  

When I want to query the item with the pg_id 16, I do this,

SELECT * 
FROM root_documents 
WHERE root_documents.pg_id = '16'

While when I want query the item without any pd_id, I do this,

SELECT * 
FROM root_documents 
WHERE root_documents.pg_id IS NULL

I find two queries are repetitive, so I try to this,

SELECT * 
FROM root_documents 
WHERE (root_documents.pg_id = ? OR root_documents.pg_id IS NULL)

So when I want to get this result only when I query the item with pg_id 16,

doc_id  doc_title   doc_order   pg_id 
12      c.zip       1           16  
13      d.zip       2           16      
3       f.doc       3           16      
4       g.doc       4           16

But I get all of them intead!

doc_id  doc_title   doc_order   pg_id 
14      a.zip       1           NULL    
15      b.zip       2           NULL    
12      c.zip       1           16  
13      d.zip       2           16      
3       f.doc       3           16      
4       g.doc       4           16

How can I fix this query,

SELECT * 
FROM root_documents 
WHERE (root_documents.pg_id = ? OR root_documents.pg_id IS NULL)

Or do I have to repeat the query like I usually do?

EDIT:

This answer looks strange to me when I have a parameter to be passed into the placeholder:

SELECT *
FROM root_documents
WHERE (root_documents.pg_id = '16' OR (root_documents.pg_id IS NULL AND '16' IS NULL))

and when without a parameter,

SELECT *
FROM root_documents
WHERE (root_documents.pg_id = NULL OR (root_documents.pg_id IS NULL AND NULL IS NULL))

Note that I pass NULL into the placeholder when no value is returned.

  • 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-24T17:53:47+00:00Added an answer on May 24, 2026 at 5:53 pm

    I think you want something like this:

    SELECT * 
    FROM root_documents 
    WHERE (root_documents.pg_id = ? OR (root_documents.pg_id IS NULL AND ? IS NULL))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named Info of this schema: int objectId; int time; int
I have this array that store the connection info and i want to use
I have this piece of code for (element <- table.find; Right(info) = exceptionManager(mapper.getInfoFromDbObject(element))) yield
i have this: Dim split As String() = temp_string.Split(,) ''#feed all info into global
I have data that looks like this: #info #info2 1:SRX004541 Submitter: UT-MGS, UT-MGS Study:
So what I have right now is something like this: PropertyInfo[] info = obj.GetType().GetProperties(BindingFlags.Public);
I have a label on my asp.net page, it looks like this: more info
I have been searching for info on this to no avail. The context of
I have found some info on the subject ( like this link) , but
I have three tables...users, user_info, and quota_levels. They look like this: CREATE TABLE users

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.