Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query help

Status
Not open for further replies.

stigissimo

Technical User
Joined
Feb 20, 2007
Messages
2
Location
NL
Can someone help me make a query?

I have a table with a companyid, employee_id and a interest_id,This could look like this:

comp_id...empl_id...int_id
1...............1.................1
1...............1.................2
1...............1.................3
1...............2.................2
2...............8.................1
2...............8.................3

I'am looking employees of companies who are only interested in 1 and 3( in this case only com 2 empl 8, and not com 1 empl 1). I'am also looking for employees of companies who are only interested in id 2(that would be only com 1 empl 2)

I hope someone can help me with this.

Kind regards

Erik
 
Some starting points:
employees of companies who are only interested in 1 and 3
SELECT comp_id, empl_id
FROM yourTable
GROUP BY comp_id, empl_id
HAVING MIN(int_id)=1 AND MAX(int_id)=3 AND COUNT(*)=2

employees of companies who are only interested in id 2
SELECT comp_id, empl_id
FROM yourTable
GROUP BY comp_id, empl_id
HAVING MIN(int_id)=2 AND MAX(int_id)=2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
tnx for you help, helped a lot!
 

If you're looking for all the employee itersted in int_id 1 or 3 try this:

Code:
SELECT comp_id, empl_id
FROM yourTable
WHERE int_id IN (1,3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top