Are there good practices when it comes to SQL queries within php? Or is there an alternative not to "dirty" the code with a giant query in the middle? Edit: What I was looking for was just views, but I did not know the name to look for, the answer chosen heals all my doubts.