MySQL Saved Queries

by damonp on June 12, 2007

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: 3% [?]

Leave a Comment

Previous post:

Next post: