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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:47:41+00:00 2026-06-17T16:47:41+00:00

Sqlfiddle is http://sqlfiddle.com/#!2/7df50/4 Basically, I have 3 tables: group, membership, client. tbl.client = client_id

  • 0

Sqlfiddle is http://sqlfiddle.com/#!2/7df50/4

Basically, I have 3 tables: group, membership, client.

tbl.client = client_id (PK, AI), industry_id (FK), status
tbl.membership = membership_id (PK, AI), Client_id (FK to tbl.client), 
    group_id (FK to group), status
tbl.group = group_id (PK, AI), target_market_id (FK), geography_id (FK)

Basically, I want to select a group_id by joining all 3 tables where NONE of the clients can have a client.industry_id equal to a given input ($client_industry_id).

My query so far is:

"select g.group_id from `group` g join membership m on m.group_id=g.group_id ".
"join client c on c.client_id=m.client_id ".
"where g.status=1 and m.status=1 and c.status=1 and ".
"g.geography_id=$target_geography and ".
"g.target_market_id=$target_market ".
"c.industry_id <> $client_industry_id";

The problem with the query is that it will still select a group_id from group because ALL clients must not have a client_id = $client_industry_id in order to trip the <>. I hope that makes sense?

Would I solve this problem via grouping? If statement?

EDIT:

insert into client (email, industry_id, status) VALUES ('email1@gmail.com', '1', '1')
insert into client (email, industry_id, status) VALUES ('email2@gmail.com', '2', '1')
insert into client (email, industry_id, status) VALUES ('email3@gmail.com', '2', '1')

insert into membership (client_id, group_id) VALUES (1, 1)
insert into membership (client_id, group_id) VALUES (2, 1)
insert into membership (client_id, group_id) VALUES (3, 2)

insert into group (geography_id, target_market_id) VALUES (1, 1)
insert into group (geography_id, target_market_id) VALUES (1, 1)

#psuedo code
"select group_id from group join membership on group_id, join client on client_id where 
    all status=1 and group.geography_id=1 and group.target_market_id=1 and 
    NONE of the clients have client.industry_id=1

-- query should result in group_id=2
  • 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-17T16:47:42+00:00Added an answer on June 17, 2026 at 4:47 pm

    You and @Strawberry are right, the previous code couldn’t have worked. Sorry about that. And Here’s a quick crack at what you might want to try instead:

    select g.group_id from groupp g 
    join membership m on m.group_id=g.group_id and m.status=1 //to consider check on status
    join client c on c.client_id=m.client_id and c.status=1 //to consider check on status
    where g.group_id not in (select mm.group_id from membership mm join client cc on mm.client_id=cc.client_id and cc.industry_id = $client_industry_id) and //to exclude groups with clients that have industry
    g.status=1 and
    g.geography_id=$target_geography and
    g.target_market_id=$target_market;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see http://sqlfiddle.com/#!3/2506f/2/0 I have two tables. One is a general record, and the
I have the following table http://sqlfiddle.com/#!3/7f078/1 Okay so what I want do is GROUP
I have 3 tables and I want to join it. Check this fiddle: http://sqlfiddle.com/#!2/20410/2
I have some data in a format described in this sqlfilddle: http://sqlfiddle.com/#!4/b9cdf/2 Basically, a
I have this database setup: http://sqlfiddle.com/#!12/b2989 I want to add a record called solrID
Following in my sql fiddle: http://sqlfiddle.com/#!2/62429/2 I have a username , which i need
Following is my sqlfiddle for testing and building the query: http://sqlfiddle.com/#!2/975c6/1 What I have
I have a table in which I'm recording logins/logouts. Schema and sample data: http://sqlfiddle.com/#!2/e1b35/1
I have the following minimal schema in Oracle: http://sqlfiddle.com/#!4/c1ed0/14 The queries I have run
I have such a schema and queries: http://sqlfiddle.com/#!2/7b032/3 Seperately I have these queries: 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.