Solved

SELECT JOIN on 3 tables

Posted on 2014-02-13
3
348 Views
Last Modified: 2014-02-13
Hi,

I need to change this MySQL request to display other field from third table.

SELECT jos_users.name, jos_acctexp_subscr.expiration
FROM jos_acctexp_subscr
LEFT JOIN jos_users ON jos_acctexp_subscr.userid = jos_users.id
WHERE jos_acctexp_subscr.status ='Active'
ORDER BY jos_users.id ASC

Open in new window



I need to display a field jos_comprofiler.member from  jos_comprofiler
JOIN jos_comprofiler.user_id
I have try different way to JOIN the third table without success

Thanks
0
Comment
Question by:lenamtl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 250 total points
ID: 39857916
Should be as simple as adding a left join to the additional table matching jos_acctexp_subscr.userid to jos_comprofiler.userid:

SELECT jos_users.name, jos_acctexp_subscr.expiration, jos_comprofiler.member
FROM jos_acctexp_subscr
LEFT JOIN jos_users ON jos_acctexp_subscr.userid = jos_users.id
LEFT JOIN jos_comprofiler ON jos_acctexp_subscr.userid = jos_comprofiler.userid
WHERE jos_acctexp_subscr.status ='Active'
ORDER BY jos_users.id ASC
0
 
LVL 9

Expert Comment

by:the_b1ackfox
ID: 39857921
Try changing this to the code below

SELECT jos_users.name, jos_acctexp_subscr.expiration
FROM jos_acctexp_subscr
LEFT JOIN jos_users ON jos_acctexp_subscr.userid = jos_users.id
WHERE jos_acctexp_subscr.status ='Active'
ORDER BY jos_users.id ASC

to:

SELECT US.name, SB.expiration, CP.Member
FROM jos_acctexp_subscr  SB
LEFT JOIN jos_users US ON SB.userid = US.id
Left join jos_comprofiler  CP on CP.user_id=US.ID

WHERE SB.status ='Active'
ORDER BY US.id ASC
0
 
LVL 25

Author Closing Comment

by:lenamtl
ID: 39857928
Thanks
it's working ok
using = jos_comprofiler.user_id
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question