title: MySQL non primary foreign key
body: <p>I'm a bit of a newbie and I can't get my head around primary keys as foreign keys. To me, foreign keys are meant to connect two rows of a table together. Therefore, it would make logical sense to use the, for example, <code>username</code> of the <code>user</code> table as a foreign key in the <code>picture</code> table. This means that the picture in that row belongs to the specified user. However, it appears that general practice favors using meaningless numbers as primary IDs. Furthermore the foreign key must/should refer to the primary key. What if I don't know the primary key, but I know another unique column, in this case <code>username</code>, how would I either get the primary key from within another MySQL statement, or alternatively have the foreign key point to a non primary key?</p>