[wp-hackers] User Meta Query Assistance

Brian Layman Brian at thecodecave.com
Tue Jan 15 18:40:52 GMT 2008


> For interest sake, I hear '...WordPress still supports MySQL 4.0, which 
> does not allow subqueries *at all* (4.1 and up;'
> so you might need to run the selects separately if its for the wild.

Bah, thanks for the reminder.  I still had the "2.1 would be 4.0 and 2.2
would be 4.1" plan in my head from way back when.  

Subqueries provide some great power and I use them for a lot of internal
stuff.  Anyone not familiar with them should really check them out.  

You can use them on inserts too, in order to add multiple rows, like this:
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES 
(NULL, (select id from `wp_users` where `user_login`='imauser'),
'first_name', 'Ima'),
(NULL, (select id from `wp_users` where `user_login`='imauser'), 'nickname',
'Ima User'),
(NULL, (select id from `wp_users` where `user_login`='imauser'),
'rich_editing', 'false')
)


One thing to remember is that mysql doesn't support insert queries don't
support subselects from the same table you are inserting to.  Temporary
views can be used to get you around that.

______________________________________________
Brian Layman
b5media Inc.
www.b5Media.com / www.TheCodeCave.com
Skype: BrianLayman
Twitter: http://www.twitter.com/brianlayman






More information about the wp-hackers mailing list