Even though this is basically a WordPress related problem, my question is strictly MySQL, so I am posting here as it probably will be more accurate.
I have two tables