Solved

Please help with SQL combination of INNER JOIN AND LEFT JOIN

Posted on 2004-08-19
13
203 Views
Last Modified: 2013-12-24
Hi,

I have an sql combination of INNER JOIN AND LEFT JOIN.  I did it in MS Access and tried to put it in my <cfquery>

Can someone please help me write this sql correctly:

SELECT tcur.CURoleid, tcur.CURolefunc, tcus.CUserID, tcus.CUlast, tcus.CUfirst,
tcus.CUMI, tcus.CUContact, tcus.CUEmail, tcus.CUDeptID, tcus.CURoleid, tcud.CUDeptID,
tcud.CUDeptNm FROM tCUserRole tcur INNER JOIN (tCUDept tcud LEFT JOIN tCUsers tcus ON tcud.CUDeptID = tcus.CUDeptID) ON tcur.CURoleid = tcus.CURoleid

the left join is neccesary because i would like to get the DeptNm.  Not all users might belong to a department so if i don't use left outer join, I will not be able to get the users that does not belong to a department.
0
Comment
Question by:mdbbound
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 11846432
Hi mdbbound,
ti shoudl work fine with CF query as CFquery do not care for anything you put between them. I have kept all the compelx thing and it is upto the database to execute that. There is no relations. You should be albe to put that in the CFQuery and it should work.

Regards,
---Pinal
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 11846505
what is the error message you are getting?
0
 

Author Comment

by:mdbbound
ID: 11846648
Oh it says joins are not supported.  

thanks
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11846665
Hi mdbbound,
that is not the error of your ColdFusion. That is ms access or any other data base you are using their error. What is your database now? mysql or other version of msacess.

Regards,
---Pinal
0
 

Author Comment

by:mdbbound
ID: 11846763
MS Access 2000.

This is actually first done in MS Access and I just followed it, retype in <cfquery>

SELECT tcur.CURoleid, tcur.CURolefunc, tcus.CUserID, tcus.CUlast, tcus.CUfirst,
tcus.CUMI, tcus.CUContact, tcus.CUEmail, tcus.CUDeptID, tcus.CURoleid, tcud.CUDeptID,
tcud.CUDeptNm FROM tCUserRole tcur INNER JOIN (tCUDept tcud LEFT JOIN tCUsers tcus ON ) ON tcur.CURoleid = tcus.CURoleid

in Access, it says that the sql is complex and I need to break it down into two.  

But how would you rewrite this in such a way that i can get the third join (left join) in tcud.CUDeptID = tcus.CUDeptID

thanks


0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11846840
Hi mdbbound,
well as guess before that this is problem with Access. I will suggest you ask this Que in MS access. Because they will know almost everything about MS Access behaviour and will guide you correct.

Regards,
---Pinal
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 17

Expert Comment

by:anandkp
ID: 11849554
If u used the Access Query Builder for creating the query - it may have got ambigious join conditins & hence may not work when u try & execute it
try executing it first in MSAcesss itself - if it runs there - then it wld also run thru CFQuery.
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 500 total points
ID: 11853646
Not always true anadkp,

I have had queries that return no results in Access itself and yet work perfectly when called via CF to access and vice versa.

The access Query tool is not very good.


THe problem seems to be missing syntax....

I would write this in cf and see what you get :

SELECT tcur.CURoleid, tcur.CURolefunc, tcus.CUserID, tcus.CUlast, tcus.CUfirst,
tcus.CUMI, tcus.CUContact, tcus.CUEmail, tcus.CUDeptID, tcus.CURoleid, tcud.CUDeptID,
tcud.CUDeptNm
FROM tCUserRole tcur
INNER JOIN tCUsers tcus ON tcur.CURoleid = tcus.CURoleid
LEFT JOIN tCUDept tcud ON tcud.CUDeptID = tcus.CUDeptID
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 11853654
Note that this probably won't work directly in access, but should work through CF
0
 
LVL 17

Expert Comment

by:anandkp
ID: 11868871
mebbe ...
its something - i have NOT come across so far ...
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 11871387
It deson't happen in most cases, but when you start getting into more complex queries (at least complex as far as access is concerned - they are still simple for other DB languages) then that is when it can happen
0
 

Author Comment

by:mdbbound
ID: 11958539
I read that CF does not support outer joins.  I'll try mrichmon's suggestion.  Sorry it has been so long, I have been so busy.

Thanks for the input everyone, i'll get back to you.
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 500 total points
ID: 11958593
You are correct, but that only applies when doing things like Query of Queries.  CF supports SENDING the Outer Join command through to a DB that does support it such as access and MS SQL
0

Featured Post

New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
X-Frame-Options - click-jacking 7 56
IIS 8.5 2 51
WAMP server installation, getting error popups, DLLs missing 5 64
System Analysis 5 51
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

24 Experts available now in Live!

Get 1:1 Help Now