Complex MySQL query with (slightly) different requirements
I have a function with a complex MySQL query over multiple tables where I check many conditions such as not-deleted, active, language, date, access rights and so forth. So it already has multiple if-else in it.
Now I need to create another query very similar to the existing one where I query only specific categories with a different order and another one where I search for keywords in the title with a relevance calculation.
I don't want to add even more if-else or copy & paste the existing query because it would create a lot of redundant and/or hard-to-maintain code.
Is there a design pattern that approaches this problem?
i am not so much clear about your requirement. i think this will may help you.
you can use first query as inline query as table in your second query but still copy paste is reburied.