?
Solved

SELECT JOIN on 3 tables

Posted on 2014-02-13
3
Medium Priority
?
356 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
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1000 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 27

Author Closing Comment

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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

807 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