Index: mythplugins/mythvideo/mythvideo/dbcheck.cpp
===================================================================
--- mythplugins/mythvideo/mythvideo/dbcheck.cpp	(revision 26887)
+++ mythplugins/mythvideo/mythvideo/dbcheck.cpp	(working copy)
@@ -88,7 +88,7 @@
     const QString lastMythDVDDBVersion = "1002";
     const QString lastMythVideoVersion = "1010";
 
-    const QString currentDatabaseVersion = "1038";
+    const QString currentDatabaseVersion = "1039";
 
     const QString OldMythVideoVersionName = "VideoDBSchemaVer";
     const QString OldMythDVDVersionName = "DVDDBSchemaVer";
@@ -1240,6 +1240,23 @@
                 return false;
         }
 
+        if (dbver == "1038")
+        {
+            QStringList updates;
+            updates += "ALTER TABLE videometadatacast ADD `sortorder` INT UNSIGNED;";
+            updates += "ALTER TABLE videometadatacast DROP INDEX idvideo;";
+            updates += "ALTER TABLE videometadatacast ADD UNIQUE INDEX (`idvideo`,`idcast`,`sortorder`);";
+            updates += "ALTER TABLE videometadatacountry ADD `sortorder` INT UNSIGNED;";
+            updates += "ALTER TABLE videometadatacountry DROP INDEX idvideo;";
+            updates += "ALTER TABLE videometadatacountry ADD UNIQUE INDEX (`idvideo`,`idcountry`,`sortorder`);";
+            updates += "ALTER TABLE videometadatagenre ADD `sortorder` INT UNSIGNED;";
+            updates += "ALTER TABLE videometadatagenre DROP INDEX idvideo;";
+            updates += "ALTER TABLE videometadatagenre ADD UNIQUE INDEX (`idvideo`,`idgenre`,`sortorder`);";
+            if (!performActualUpdate(updates, "1039", dbver,
+                                     MythVideoVersionName))
+                return false;
+        }
+
         return true;
     }
 }
Index: mythtv/libs/libmythmetadata/dbaccess.cpp
===================================================================
--- mythtv/libs/libmythmetadata/dbaccess.cpp	(revision 26887)
+++ mythtv/libs/libmythmetadata/dbaccess.cpp	(working copy)
@@ -265,9 +265,9 @@
         m_id_name(id_name), m_value_name(value_name), m_ready(false),
         m_clean_stub(this)
     {
-        m_insert_sql = QString("INSERT INTO %1 (%2, %3) VALUES (:ID, :VALUE)")
+        m_insert_sql = QString("INSERT INTO %1 (%2, %3, sortorder) VALUES (:ID, :VALUE, :SORTORDER)")
                 .arg(m_table_name).arg(m_id_name).arg(m_value_name);
-        m_fill_sql = QString("SELECT %1, %2 FROM %3 ORDER BY %4").arg(m_id_name)
+        m_fill_sql = QString("SELECT %1, %2 FROM %3 ORDER BY %4,sortorder").arg(m_id_name)
                 .arg(m_value_name).arg(m_table_name).arg(m_id_name);
     }
 
@@ -289,6 +289,7 @@
     int add(int id, int value)
     {
         bool db_insert = false;
+        unsigned sortorder = 1;
         id_map::iterator p = m_val_map.find(id);
         if (p != m_val_map.end())
         {
@@ -298,6 +299,7 @@
             if (v == va.end())
             {
                 va.push_back(value);
+                sortorder = va.size();
                 db_insert = true;
             }
         }
@@ -316,6 +318,7 @@
             query.prepare(m_insert_sql);
             query.bindValue(":ID", id);
             query.bindValue(":VALUE", value);
+            query.bindValue(":SORTORDER", sortorder);
             if (!query.exec())
                 MythDB::DBError("multi value insert", query);
         }
Index: mythtv/libs/libmythmetadata/metadatacommon.cpp
===================================================================
--- mythtv/libs/libmythmetadata/metadatacommon.cpp	(revision 26887)
+++ mythtv/libs/libmythmetadata/metadatacommon.cpp	(working copy)
@@ -137,8 +137,12 @@
 
 QList<PersonInfo> MetadataLookup::GetPeople(PeopleType type) const
 {
+    // QMultiMap reverses the order of items added, so put them back in the right order
     QList<PersonInfo> ret;
-    ret = m_people.values(type);
+    QList<PersonInfo> backwards = m_people.values(type);
+    QList<PersonInfo>::iterator iter;
+    for(iter = backwards.begin(); iter != backwards.end(); iter++)
+        ret.push_front(*iter);
     return ret;
 }
 
