Jump to content

need query help please!!!


roberthughes

Recommended Posts

I have the following 3 tables:

 

table 1: companies

fields 1: company_id, company name, status

Sample data:

1 , company 1 , 0

2 , company 2 , 1

3 , company 3 , 1

4 , company 4 , 0

5 , company 5 , 1

 

table 2: groups

fields 2: group_id, group_name

Sample data:

1 , Group 1

2 , Group 2

3 , Group 3

4 , Group 4

5 , Group 5

 

table 3: company_group_intersect

table 3: group_id, company_id

Sample data:

1 , 2

1 , 3

2 , 2

2 , 3

2 , 5

 

As you can see, Group 1 consists of Companies 2 and 3. And Group 2

consists of Companies 2, 3 and 5.

 

The query I\'m having trouble with is trying to get a result set of

(status=1) companies that AREN\'T in a particular group.

 

\"group_id\" is my only available variable passed in from the script.

 

I need a results set that has: * companies.company_name,

companies.company_id where companies.status=\'1\' and companies.company_id

is not in intersect table next to the variable group_id.

 

If I pass in group_id 1 the result set should be:

5 , company 5

 

since it\'s the only status=\'1\' company that\'s not in group 1

 

Thanks in advance for your help.

 

Robert

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.