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
Solved

SELECT JOIN on 3 tables

Posted on 2014-02-13
3
347 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 25

Author Closing Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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