Reputation: 485
I have a noob question here. I am currently developing a leads management system. Basically I have this tables as below
What im trying to do now is when a Parent (aff_id = 740) logged-in into the system, he can see all leads created by child under him (leads from aff_id 1245, 1256 & 1301)
Below is my mySQL code. Im not that good in creating a more 'complicated' queries, but this is where i got stucked.
SELECT
leads.leads_id,
leads.aff_id,
leads.applied_product,
affiliate.aff_id,
affiliate.parent_id
FROM
leads, affiliate
WHERE
leads.aff_id = '740'
OR
affiliate.parent_id = '740'
Any help is very much appreciated. Thanks in advance
Upvotes: 0
Views: 493
Reputation: 9066
run the following query.If i understood you correctly this is something you are looking for.It will fetch all the data from leads table that's aff_id is associated with parents_id= 740 in affiliate table
SELECT
Leads.leads_id,
Leads.applied_products,
Leads.aff_id,
Affiliate.parent_id
FROM
Leads
INNER JOIN
Affiliate
ON Leads.aff_id = Affiliate.aff_id
WHERE Affiliate.parent_id = 740
Upvotes: 1