If you find yourself performing the same queries again and again, it might help to use stored procedures. These are like named functions within a DBMS - you define a sequence of instructions to perform, and give it a name. Whenever you want that same set of instructions to be performed, you simply run the procedure - the results often come back faster because the DBMS has already prepared the query in advance, and so knows how to run it quickly.
One big advantage to stored procedures is that they remain on the DBMS - if you want to change a procedure so that it does something different, you need only change it once, on the server, to have all the programming code that calls it updated also.
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!