Solved

Please help with SQL combination of INNER JOIN AND LEFT JOIN

Posted on 2004-08-19
13
202 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
Comment Utility
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
Comment Utility
what is the error message you are getting?
0
 

Author Comment

by:mdbbound
Comment Utility
Oh it says joins are not supported.  

thanks
0
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
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
Comment Utility
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
Comment Utility
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 17

Expert Comment

by:anandkp
Comment Utility
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
Comment Utility
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
Comment Utility
Note that this probably won't work directly in access, but should work through CF
0
 
LVL 17

Expert Comment

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

Expert Comment

by:mrichmon
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

11 Experts available now in Live!

Get 1:1 Help Now