This below is abstraction. Queries are much more complex. Principle exactly the same.
I have a Stored Procedure that does:
SELECT * FROM T1
WHERE T1.fk IN (SELECT id FROM T2);
In reality this inline query is very complex and is being used in many other stored procedures. I wish to maintain it's code in only one place. Right now, the worst case scenario, is this inner query returns about 22K records.
How do I put this inner query in only one place (as a function, something like include,macro etc...)
Efficiency is not important in this case. Maintainability less code, is.