Kyle.Belanger Kyle.Belanger - 1 year ago 84
MySQL Question

Combining 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.

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

# multiple select from tables
select, group.ID
from user as u, group as g
where = <name_here>

# inner join...
select user.ID, group.ID,
from user
inner join group
on user.ID = group.ID

I need to select the and group.ID based on a username param. Is there a way to query this data in a single statement?

Answer Source

I don't know if I understand your need, lets try:

Try to use this query:

select pGroupMatch.GroupID, ProfileData.ID
from pUserMatch
inner join pGroupMatch on pGroupMatch.GroupID = pUserMatch.GroupID 
inner join ProfileData on = pGroupMatch.ProfileID 
where pUserMatch.username = "<username>";

Check if you can create indexes for improve your query, if you can try it:

CREATE INDEX idx_pUserMatch_01 ON pUserMatch (GroupID);
CREATE INDEX idx_pGroupMatch_01 ON pGroupMatch (ProfileID);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download