I have 2 tables,
accounts. When inserting into
accounts I fetch the ID of the rank first, storing it in a variable on the script running the queries, then insert the new account into the table with the rank ID. How could I combine this into a single MySQL statement?
// This is pseudo code. var acct = GetAcct() var a = MySQL.query("SELECT `id` FROM `ranks` WHERE `name`=" + acct.rankName).firstResult() var b = MySQL.query("INSERT INTO `accounts` (`sid`, `did`,`rank`) VALUES (" + acct.sid + "," + acct.did + "," + a + ") ON DUPLICATE KEY UPDATE `did`=" + acct.did + ",`sid`=" + acct.sid + ", `rank`=" + a)