Combining 3 select queries I am working with a MySQL database. I am suppose to combine three select queries, to "improve performance". Each select below is dependent on the previous ID retrieved. 

Here is the workflow to get data references between the tables. 

There are three tables:

pUserMatch  |  pGroupMatch  |  ProfileData
----------- |  -----------  |  ----------
* username 
* GroupID .... GroupID
               ProfileID ....  ID 
                               ParentUser


My three select queries...

# get the group ID for the specific username
group_id = select GroupID from Profiles.pUserMatch where username = "&lt;username&gt;";

# now, get the group match ID for the group ID
profile_id = select ProfileID from Profiles.pGroupMatch where GroupID = "&lt;group_id&gt;"

# now, get the profile data for this ID
profile = select * from Profiles.ProfileData where ID = "&lt;profile_id&gt;"


I know a little bit about using joins, but I thought that they were only used when multiple tables have matching data.

So far, I've tried the following...

# multiple select from tables
select usermatch.username, groupmatch.GroupID
  from pUserMatch as usermatch, pGroupMatch as groupmatch
  where usermatch.username = &lt;"username"&gt;

# inner join...
select pUserMatch.GroupID, pGroupMatch.GroupID,
  from pUserMatch
    inner join pGroupMatch
      on pUserMatch.GroupID = pGroupMatch.GroupID


I need to select the pGroupMatch.GroupID and ProfileData.ID based on a username param. Is there a way to query this data in a single statement?
As far as I know you don't need foreign keys to make joins.

Also, you don't even need to use the "inner/outer join" syntax to make joins!

So, following your schema:

pUserMatch  |  pGroupMatch  |  ProfileData
----------- |  -----------  |  ----------
* username 
* GroupID .... GroupID
               ProfileID ....  ID 
                               ParentUser


The query would be:

select u.username, u.GroupID, g.ProfileID, p.ParentUser
from pUserMatch u, pGroupMatch g, ProfileData p
where u.GroupID = g.GroupID
  and g.ProfileID = p.ID
  and usermatch.username = &lt;"username"&gt;


Anyway the "join" syntax would be the following:

select u.username, u.GroupID, g.ProfileID, p.ParentUser
from pUserMatch u
  inner join pGroupMatch g
    on u.GroupID = g.GroupID
  inner join ProfileData p
    on g.ProfileID = p.ID
 where usermatch.username = &lt;"username"&gt;


Use "left outer join" instead of "inner join" if you want to see all the records of the first table (i.e. pUserMatch) even if there's no the linked record on the other one (i.e. pGroupMatch).