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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:51:07+00:00 2026-05-28T20:51:07+00:00

I am trying to fetch records from 2 tables mapped by an id where

  • 0

I am trying to fetch records from 2 tables mapped by an id where on the second table there may be a row that is missing.

I have a column called name on the second table which contains a string value. The value I need to extract is ‘subscriptions’ but this does not always exist in the table. There is the possibility to have different values within this column which I do not want to extract.

Is it possible to check to see if the value exists and if it doesn’t output null to all the fields.

So far I have this which returns all the records

select COUNT(*) 
from PUser a, PAttribute b
where exists (select null 
              from PAttribute c 
              where c.name = 'subscriptions' or c.name is null) 
   and a.id = b.userid;

Hope that explains it.

EDIT

PUser table

id
other columns

PAttribute table

userid mapped to PUser.id
name

Now a userid can have multiple rows each with a different value in name eg, ‘subscriptions’, ‘source’, ‘etc’ ‘etc’

I want to fetch all users who have the value ‘subscriptions’ in the name column or if the row doesnt exist with the value ‘subscriptions’ as they may not have any.

If they don’t have this row the output should be null.

EDIT 2:

Worked this out and I needed

select COUNT(*),(select b.stringValue from PAttribute b where b.userid = a.id and b.name = 'subscriptions') from PUser a order by a.id desc;
  • 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-28T20:51:08+00:00Added an answer on May 28, 2026 at 8:51 pm

    Your example is using implicit joins, which are inner joins. This means that a result will only be returned if a row exists in both tables. Instead, you need to use a left join. Change your query to this:

    select COUNT(*)  
    from PUser a LEFT JOIN PAttribute b ON a.id = b.userID
    where exists (select null  
                  from PAttribute c  
                  where c.name = 'subscriptions' or c.name is null);
    

    Or (not exactly sure what your desired behavior is), this might work for you:

    SELECT count(*)
    FROM PUser a LEFT JOIN PAttribute b ON a.id = b.userID
    WHERE b.name = 'subscriptions' OR b.name IS NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fetch all records from my table on my site, I have
I am trying to fetch some records from table but when i use OR
I am trying to fetch records from the table using the below sql query.
I am trying to fetch out records from left table only those records which
I'm trying to query a table, fetch all records, and save the result as
I'm trying to fetch data from a page that resides on an intranet. The
I am trying to fetch wcf service from jquery. I have written below code
I am trying to join 2 tables and trying to fetch the records, which
I have a Dataset that contains tables from a university database, two(actually more) of
I am trying to fetch records based on two dates from sql server... Select

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.