MySQL Saved Queries

by damonp on June 12, 2007

in General

phpMyAdmin‘s SQL popup has an interesting bookmarking feature called SQL History.

PMA SQL History

I have plenty of saved queries to produce different reports on many of the client databases that I administer. I was looking for a way to supply a variable to search on in some of the queries. A little trial and error with the SQL bookmarks and the answer was right there.

If you need to use a query like this:

SELECT sum( products_weight ) AS total_weight FROM products WHERE products_id IN ( SELECT products_id FROM orders_products WHERE orders_id = '10204' )

But you need to lookup specific orders and need to pass an orders_id to the bookmarked query… create a bookmark like this

SELECT sum( products_weight ) AS total_weight FROM products WHERE products_id IN ( SELECT products_id FROM orders_products WHERE orders_id = '/*[VARIABLE]*/' )

phpMyAdmin will replace the placeholder

/*[VARIABLE]*/

with the variable entered in to the field at right.

Bookmarks seem to be unique to the database that is selected. I found this out the hard way when I was editing a different database and tried to access bookmarks from another DB on the same server.

Popularity: 4%

Most Popular Posts

Damon Parker is a freelance sysadmin and web developer in Texas. He specializes in server setup, server security and high performance server configurations. Need help setting up a web server or getting a server back online after a crash or hack? Email Damon

Leave a Comment

Previous post:

Next post: