Solved

SELECT JOIN on 3 tables

Posted on 2014-02-13
3
341 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 250 total points
Comment Utility
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
Comment Utility
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 24

Author Closing Comment

by:lenamtl
Comment Utility
Thanks
it's working ok
using = jos_comprofiler.user_id
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Creating and Managing Databases with phpMyAdmin in cPanel.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now