473,508 Members | 2,104 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 3529
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,557 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
1756
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....
2
2055
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...
3
4248
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,...
0
1156
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...
52
6270
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...
4
1572
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...
0
1417
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...
0
1261
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...
0
1052
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...
1
1034
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...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
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...
0
5631
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,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
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...
0
3199
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...
0
1561
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 ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
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...

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.