I ran into a problem or maybe even a MySQL limitation.
The situation is as follows:
I have an SP X, selecting related records based on 1 or 2 arguments. The SP returns a list of 0, 1 or more id’s. I wanna use that list in an IN clause like so:
SELECT
*
FROM
table
WHERE
id IN (spX(y));
This gives me an error:
Syntax error or access violation: 1305 FUNCTION z.spX does not exist
The error is a bit vague: I’m confident it’s a syntax error rather than access violation or non-existence of the SP itself. If I CALL the SP directly I get my expected results.
This kinda feels like a dead end. My expectation was that MySQL would throw an error if the SP returned more than 1 column, not if it returned more than 1 row (in which case I could’ve used a FUNCTION instead and this would’ve worked straight away).
So, the question is: is there any way of using the SP’s result in an IN clause?
On a side note: I’m aware I could achieve the same result by simply joining the table and then add a new where clause to the existing query, instead of using the SP. However, the real problem here is that new functionality has to be added to the application, and not having to join in tons of queries, but using a SP instead is the way of least resistance.
I implemented the solution as proposed in the chat:
https://chat.stackoverflow.com/rooms/12910/discussion-between-robin-v-g-and-hituptony
What I do step by step:
This way I can always add or alter the conditions in the SP itself, without changing the application logic/queries.