Solved

SELECT JOIN on 3 tables

Posted on 2014-02-13
3
343 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
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 24

Author Closing Comment

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now