I'm having a problem with a self join. Here is how I wrote the query:
SELECT s.ssn, count(g1.ssn) as Count1, count(g2.ssn) as Count2
FROM security s, grads g1, grads g2
WHERE s.ssn*=g1.ssn AND
s.ssn*=g2.ssn AND
g1.role='Major' AND
g2.role='Co-Major'
GROUP BY s.ssn
--The problem is that my numbers come out wrong-I think rows are being counted twice between the two 'grads' tables. Obviously, if I write two queries I get the correct numbers. But if possible I want the 3 columns (ssn, Count1, Count2) all in the same query.
I thought about using views, but I need to pass parameters and I'm not sure you can pass parameters into a view.
SELECT s.ssn, count(g1.ssn) as Count1, count(g2.ssn) as Count2
FROM security s, grads g1, grads g2
WHERE s.ssn*=g1.ssn AND
s.ssn*=g2.ssn AND
g1.role='Major' AND
g2.role='Co-Major'
GROUP BY s.ssn
--The problem is that my numbers come out wrong-I think rows are being counted twice between the two 'grads' tables. Obviously, if I write two queries I get the correct numbers. But if possible I want the 3 columns (ssn, Count1, Count2) all in the same query.
I thought about using views, but I need to pass parameters and I'm not sure you can pass parameters into a view.