I have this query, which works:
SELECT DISTINCT sid, name, last_name, tuition
FROM students
WHERE EXISTS (SELECT * FROM payments
WHERE payments.forMonth = 'May'
AND students.sid = payments.sid)
However, when I try to add a couple columns from the payments table, the query fails:
SELECT DISTINCT students.sid, students.name, students.last_name,
students.tuition, payments.amount, payments.forMonth
FROM students payments
WHERE EXISTS (
SELECT *
FROM payments
WHERE payments.forMonth = 'Apr'
AND students.sid = payments.sid)
I've tried this with an inner join in the top-half of the query, but that generated wrong results. Is there a way to do this?
(The reason for the EXISTS condition is that I'll have a toggle on the filter form that will show either payments made or payments not made.)