473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Outer Right Join on SubQuery

171 New Member
Hi Everyone,

I am new to SQL Server, but have played around with MS Access a fair bit.

I am currently trying to create an Outer Right Join on a Table and Query in SQL Server. Heres query from Access Query builder below:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblPhone.custID, NotMobile.CustMoreThanMob
  2. FROM NotMobile RIGHT JOIN tblPhone ON NotMobile.CustMoreThanMob = tblPhone.c_uid
  3. WHERE (((NotMobile.CustMoreThanMob) Is Null));
Notes:
1. tblPhone is a Table and it contains the field CustID
2. NotMobile is a Query and it contains the field CustMoreThanMob
2.Heres the query that defines "NotMobile" in the above query:

Expand|Select|Wrap|Line Numbers
  1. SELECT Left([PhoneNumber],3) AS Type, tblPhone.custID AS CustMoreThanMob 
  2. FROM tblPhone
  3. GROUP BY Left([PhoneNumber],3), tblPhone.custID
  4. HAVING (((Left([PhoneNumber],3))<>614));
I have tried to get the top query to run in SQL Server in the following ways:
1.
Expand|Select|Wrap|Line Numbers
  1. SELECT custID, CustMoreThanMob
  2. FROM NotMobile OUTER RIGHT JOIN tblPhone ON NotMobile.CustMoreThanMob = tblPhone.c_uid
  3. WHERE CustMoreThanMob Is Null;
* Please note that all instances of the query "NotMobile" have been replaced by the words "NotMobile" . In the actaul query I have put the whole SQL String in round brackets.


Thank You in Advance
May 31 '11 #1
2 3533
gpl
152 New Member
I dont have SQL Server with me, so I cannot verify the code

Basically, your sub query needs to be set up as a derived table so that it can be joined.

Many years ago I read an article that said SQL Server is optimised for Left (as opposed to Right) outer joins, so have re-written it that way.

This should get you started
Expand|Select|Wrap|Line Numbers
  1. SELECT tblPhone.custID, NotMobile.CustMoreThanMob
  2. FROM  tblPhone    left outer join
  3. (
  4.   SELECT Left([PhoneNumber],3) AS Type, tblPhone.custID AS CustMoreThanMob
  5.   FROM tblPhone
  6.   GROUP BY Left([PhoneNumber],3), tblPhone.custID
  7.   HAVING (((Left([PhoneNumber],3))<>614)) 
  8. ) NotMobile
  9.  
  10. ON NotMobile.CustMoreThanMob = tblPhone.c_uid
  11. WHERE (((NotMobile.CustMoreThanMob) Is Null))
May 31 '11 #2
NeoPa
32,568 Recognized Expert Moderator MVP
You don't seem to say what your actual problem is, but in case it helps, the RIGHT OUTER JOIN is a type of outer join qualified by RIGHT. Not a type of right join qualified by OUTER.

MSSQL can be very forgiving, so I can't say what you've used will necessarily fail (and I have no info from you on the matter) but I wouldn't expect that to work.

In Jet SQL (used by Access) that you're more used to there is only support for the LEFT & RIGHT OUTER JOINs (just called LEFT JOIN & RIGHT JOIN generally) but MSSQL also supports the third type (FULL) of OUTER JOINs.

SQL JOINs may be of some help.
May 31 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1761
by: Joerg Ammann | last post by:
hi, os: aix 4.3.3 DB2: version 7 FP3 we are using a federated DB setup, datasource and fed-Db are both V7FP3 (in fact they are on the same server) and are having massiv performance problems. i tracked it back to the way the queries are push-downed to the
2
2062
by: Beowulf | last post by:
The problem: I'm updating a report to be "multi-language" capable. Previously, any items that had text associated with them were unconditionally pulling in the English text. The database has always been capable of storing multiple languages for an item, however. Desired output: Given the test data below, I'd like to get the following results select * from mytestfunc(1)
3
4260
by: BigGuy316 | last post by:
strSQL = "SELECT tblf107grpDept.DeptName AS Org, tblUsers.UserFName + ' ' + tblUsers.UserLName AS Requestor,CONVERT(varchar, tblF107Log.RecDate) + ' EST' AS , tblF107Log.Comments AS Comments, tblF107Log.IDFrm FROM dbo_tblF107grpDept RIGHT JOIN tblUsers ON tblF107grpDept.IDDept = tblUsers.IDDeptfk RIGHT JOIN tblF107Log ON tblUsers.UserID = tblF107Log.IDContact WHERE IDFrm = " & request.querystring("IDForm") & ";" Set rsCoordinationSection...
0
1162
by: Viendra | last post by:
I am attempting to determine which of the following Program Cods(A) below are ]not contained within the Program Tranlation Code Table (B) using the follwing SQL query: SELECT DISTINCT . FROM Program_Translation RIGHT JOIN ON Program_Translation.ID = .ID WHERE (((.)<>"CC-P")); The output of the query is listed below (C). I used basically the same query for determining Product Lines(A1) not contained within an productline tranlation...
52
6312
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
4
1583
by: cihpet | last post by:
Hallo, I am beginner, I want to show on page results of this query: $query="SELECT mr_prehlad.mr_id, mr_kontakt.nazov_mr FROM mr_prehlad RIGHT JOIN mr_kontakt ON mr_kontakt.id_mr=mr_prehlad.mr_id WHERE mr_prehlad.'$co'='1' ORDER BY mr_prehlad.mr_id "; But this while ( $row = MySQL_Fetch_Field( $result ) ) { echo "<tr>\n"; foreach( $row as $hodnota ) { echo "<td>\n"; echo $hodnota; echo "</td>\n";
0
1429
by: qarmoe | last post by:
Please open the Screen Print (attached), else it's not gonna makes sense... http://download.yousendit.com/A61005CA7194C418 SELECT DISTINCT MSysObjects.Name FROM MSysObjects WHERE (((MSysObjects.Name) Not Like "msys*" And (MSysObjects.Name) Not Like "all*") AND ((MSysObjects.Type)=1));
0
1271
by: qarmoe | last post by:
Is there a vb that can create right join from a static table to all the table names resulting from the query below ? SSID is the common fields in all the tables. This query gives all the temp tables SELECT DISTINCT MSysObjects.Name FROM MSysObjects WHERE (((MSysObjects.Name) Not Like "msys*" And & _
0
1060
by: rouch | last post by:
After a month of troubleshooting, I am at a loss, and hope some good soul here can help. I have three tables UCC, Acknowledgement, BSD. I need to create a record in the BSD table, have accounts in the UCC table review the BSD record, and acknowlege the record. After they acknowledge it, I want a line item to be created in the Acknowledgement table. I need accounts in the UCC table to view only the BSD's they have acknowledged and the BSD's...
1
1045
by: Giorgio | last post by:
Hi, I have a table with a date_created and date_expired and I want to look at the 15th of each month and every month since the system started and count up how many accounts were active at each of those points in time. Will have to assume that if there's an expiry date bigger than today then that account was active at each of those points in time. I created a numbers table from 1 to 100. I have the following code working well in...
0
8448
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.