The third line of each of these statements is exactly the same:
statement1
SELECT * FROM `uploads`
WHERE `uid` = :uid
AND `deleted` <> 1 AND `archived` <> 1
statement2
SELECT * FROM `uploads`
WHERE `folder_id` = :folder_id
AND `deleted` <> 1 AND `archived` <> 1
The third line is used in many other statements as well, lets say 30 different statements; in this contrived example it means "we get all files from an uploads table...that have not been deleted or archived". If in the future we need to add a third qualifier to it (e.g. AND uploadsuccess = 1
) we would have to edit 30 different sql statements. Not DRY at all. How can we use DRY principles here, via SQL (MySQL in our case, if that is an important factor)?
Thanks for any help.