How would I write this query and not get the error, "Subquery returns more than one row"?
Posted on 2016-08-24
I've got a table that reflects a payment has recently been made and it has a id of 6558.
In an other table, I've got a column called "payment_id" and it has in the same row another column called "programs."
I want to find out in the context of a single SELECT statement whether or not the "program" that corresponds to that payment is one of several types. I wrote it like this:
select p.* from payment p where p.student_id='51' OR p.sibling_1='Kimberley Oakley' OR p.sibling_2='Kimberley Oakley' OR p.sibling_3='Kimberley Oakley' AND p.id = (select pr.payment_id from programs pr where pr.program='After School' OR pr.program='Night Classes' OR pr.program='Camp' or pr.program='Hapkido' OR pr.program='Krav Maga') order by p.payment_date DESC LIMIT 1
So, I'm looking for one payment in the payment table and I want to ensure that the only payments returned in my recordset were payments for either the "After School" program, the "Night Classes" program, the "Camp" program, "Hapkido" and "Krav Maga."
There shouldn't be more than one row in the subquery, since there's only one payment id. What am I doing wrong?