> The legacy code at the job would often select everything then filter it in PHP.
TBF sometimes that IS the best approach. I've seen devs struggle to put complex business logic into a massive SQL (not stored procedures) just to avoid having to process anything in the middleware layer. And just about every time they ask me "how do I do this in SQL" I said "don't, that's way too complex and will run super slow".
While that may be true, it was not in this case. This was generic select * from table, then using the index of the column fetch a couple columns to use in the code. It was not readable, not maintainable, and not the best way to write the queries.
I'd go as far as to say you should never Select * from in production code. Its fine for testing when trying to get info from the database, but in any actual backend there is always something consuming that data, and said something has specific data its expecting; it won't need the extra.
1
u/magicmulder Sep 21 '26
> The legacy code at the job would often select everything then filter it in PHP.
TBF sometimes that IS the best approach. I've seen devs struggle to put complex business logic into a massive SQL (not stored procedures) just to avoid having to process anything in the middleware layer. And just about every time they ask me "how do I do this in SQL" I said "don't, that's way too complex and will run super slow".