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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:17:16+00:00 2026-06-18T11:17:16+00:00

We store our accounts information in a PostgreSQL database. Accounts are in the accounts

  • 0

We store our accounts information in a PostgreSQL database.

Accounts are in the “accounts” table, groups in the “grp” table, and they’re tied together by the “account_grp” table, which maps account_id to grp_id.

I’m trying to craft a query which will give me a view which lets me search for whether members of one group are members of another group, i.e. I want an “is_in_foobar_group” column in the view, so I can SELECT * FROM my_view WHERE grp_id = 1234; and get back

username | is_in_foobar_group | grp_id 
---------+--------------------+-------
bob      | true               | 1234
alice    | false              | 1234

The foobar bit is hardcoded, and will not need to change.

Any suggestions?

  • 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-18T11:17:17+00:00Added an answer on June 18, 2026 at 11:17 am

    Maybe using the EXISTS operator would help:
    http://www.postgresql.org/docs/9.2/static/functions-subquery.html#FUNCTIONS-SUBQUERY-EXISTS

    I’m not sure you can use it in a SELECT statement, and I don’t have a PostgreSQL instance to check it.
    Worst case you’ll have to do 2 queries, something like:

    SELECT username, true, grp_id 
    FROM accounts a INNER JOIN account_grp g1 on a.account_id = g.account_id
    WHERE EXIST (SELECT 1 FROM account_grp g2 
        WHERE g2.account_id = a.account_id and g2.grp_id = [foobar])
    UNION
    SELECT username, false, grp_id 
    FROM accounts a INNER JOIN account_grp g1 on a.account_id = g.account_id
    WHERE NOT EXIST (SELECT 1 FROM account_grp g2 
        WHERE g2.account_id = a.account_id and g2.grp_id = [foobar])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 100000 Ids to store into our DataBase. Id is in string format.each
Our Magento store uses the Website Payments Pro payment gateway through PayPal. For the
Our software has data to store, so it also install MYSQL, a root user
Our business currently has an online store and recently we've been offering free specials
i wanted to know where we should store the db in our project and
In one page of our site, I have this code: $_SESSION['returnURL'] = /store/checkout/onepage; and
I just submitted a new version of our app to the Apple app store,
Our web app needs to be made PCI compliant, i.e. it must not store
I am doing building an application for an app-store market. They gave me following
If we remove one of our apps from the iPhone app store what is

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.