The context here is migrating users from an existing Drupal 6 site to a new site that no longer uses Drupal - or any other CMS. Drupal, at least in v6, used a rather complex mechanism for storing additional user data
- User data went into a
users
table - you defined data keys in a separate table called
profile_fields
- and the actual values in a table called
profile_values
.
profile_values and users shared a uid field. In my new site I am using a single users table which is structured something like this
CREATE TABLE IF NOT EXISTS `users` (
`uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`rname` varchar(64)...
In the original Drupal profile_values table the rname entry for each user (distinct uid) is identified by that uid and an 'fid' of 14.
CREATE TABLE IF NOT EXISTS `profile_values` (
`fid` int(10) unsigned NOT NULL DEFAULT '0',
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`value` text,...
What I need to do is execute a bit of SQL which will pick up the right value (for uid = UID & fid = 14) from the profile_values table and update the users table. I vaguely suspect that this will require using INNER JOIN etc but that is well beyond my level of SQL skills (my poorest suite). I would much appreciate any tips on how this can be accomplished.
An illustration of what I am after may help here
user
Table (Before)
uid name rname
1 Any - empty prior to operation
2 Eny - empty prior to operation
profile_values
Table
uid fid value
1 13 v1-13
1 14 v1-14
2 11 v2-11
3 14 v2-14
user
Table (After)
uid name rname
1 Any v1-14
2 Eny v2-14