Buy Now
Sign in

Relating two tables with foreign key

kkurtz , January 01 at 00:05
I am trying to relate two tables: one is the Joomla users table (primary key is id) and the other is a user information table. Both tables contain the username. But I don't want to make the primary key the username in the information table because I need to allow multiple records for some of the usernames. How can I use the foreign key to match the two tables? I would rather not force the second table to have the id field if I can help it.

Thank you,
Hi Karen,

The usual setup is to have the 2nd table have a field named "user_id" which contains the user id from the first table, then you can use user_id as the foreign key and select the relation type as "multiple matching" if you are going to have multiple records per user.

Best regards
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
So I guess I'll have to find a way to add the user_id to my second table.

Thanks, Max