# Solved: Link Tables in MySQL



## support.clpafs (Apr 7, 2008)

ok, so I have a table "Users" which stores the following user information:
* ID
* AccessLevel
* Username
* Password
* Status
* LastLogin
* RegistrationDate

and another "Profile" which stores the following user information that is relative to their account:
* ID
* Age
* City
* Country
* DisplayName
* EmailAddress
* Expression
* FirstName
* Gender
* LastName
* Mood
* Photo
* Saying
* State

Ok, now here is my delima, I use the table "Users" to check the username and password at Login, and to "sort" pages according to username.

Now, when I try to "sort" the page to show specific user date according to the username that data from the table "Users" is available for use, as far as the table "Profile" is not, because I cannot sort by ID, is there anyway I can link the tables together without having to place a field "Username" in the "Profile" table?


----------



## colinsp (Sep 5, 2007)

The better (proper?) way to achieve what you want is to store users_id (the id from the users table) in your profiles table and then perform a 'join' on the two tables or just run a second query using user_id as your source against the profiles table.


----------



## support.clpafs (Apr 7, 2008)

Well that's the thing the "ID" in both tables is their unique user Profile ID


----------



## support.clpafs (Apr 7, 2008)

ok, so looking into the advice that was given by "colinsp" I was able to solve my issue with the two databases by "joining" them together.

SELECT *
FROM Users, Profile
WHERE Username = colname AND Users.ID = Profile.ID


----------

