473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

NOT IN Subquery returns no records

7
The following query results no records. I am trying to exlude the Counter party Descriptions present in the Adjustments table, from the results of the main query. Any help is appreciated.

SELECT TOP 10 Counterparty.[Counter Party Description], Counterparty.[Entity Short Name] AS Entity, Counterparty.[Current Exposure Short] AS [Current Exposure], Counterparty.[Applied Nettable Cash Collateral Short] AS [Applied Nettable Cash Collateral], Counterparty.[Cash Collateralized CE Short] AS [Cash Collateralized CE], Counterparty.[NonNettable Cash and Security Collateral Short] AS [NonNettable Cash and Security Collateral]
FROM Counterparty
WHERE Counterparty.[Desk Name]="COMMODITIES"
AND Counterparty.[Cash Collateralized CE Short]<>0
AND counterparty.[Counter Party Description] NOT IN (SELECT DISTINCT adjustments.[Counter Party Description] FROM adjustments WHERE adjustments.[Desk Name] = "COMMODITIES")
ORDER BY Counterparty.[Cash Collateralized CE Short];
Jun 1 '07 #1
4 1681
MMcCarthy
14,534 Expert Mod 8TB
I'm not sure what the size or data type of this desciption field is but you could try the following:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT TOP 10 Counterparty.[Counter Party Description], Counterparty.[Entity Short Name] AS Entity, Counterparty.[Current Exposure Short] AS [Current Exposure], Counterparty.[Applied Nettable Cash Collateral Short] AS [Applied Nettable Cash Collateral], Counterparty.[Cash Collateralized CE Short] AS [Cash Collateralized CE], Counterparty.[NonNettable Cash and Security Collateral Short] AS [NonNettable Cash and Security Collateral]
  3. FROM Counterparty LEFT JOIN adjustments
  4. ON (counterparty.[Counter Party Description] = adjustments.[Counter Party Description] 
  5. And Counterparty.[Desk Name] = adjustments.[Desk Name])
  6. WHERE Counterparty.[Desk Name]="COMMODITIES" 
  7. AND Counterparty.[Cash Collateralized CE Short]<>0 
  8. AND adjustments.[Counter Party Description] Is Null
  9. ORDER BY Counterparty.[Cash Collateralized CE Short];
  10.  
Jun 2 '07 #2
rishhh
7
Thanks a lot for your help. I highly appreciate it.

However, I still have one more problem. The 'adjustments' table may not have all the desk names, but will have only those desk names, which have some adjustments. So I can't use this query for desk names with no entry in adjustments table, as it returns nothing.

In each of the reporting cycle, the desks having adjustment would be different. So i am trying to find a generic criteria which will work in any case.

The # of records is small (about 70K records in 15 cols). Unfortunaltely, there are several limitations due to which i cannot use the normal database design techniques. i am using access as a temp storage space where i sort/aggregate the data and link it back to excel. The data is such that I cannot define primary keys on tables. But most of my queries are on single tables, do not involve joins, except for the one under consideration.

Thanks a million. I highly appreciate it.
Jun 4 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanks a lot for your help. I highly appreciate it.

However, I still have one more problem. The 'adjustments' table may not have all the desk names, but will have only those desk names, which have some adjustments. So I can't use this query for desk names with no entry in adjustments table, as it returns nothing.
As I've used a LEFT JOIN this should return all records from the adjustments table. The following line excludes matching records

AND adjustments.[Counter Party Description] IS NULL

Remove it and see what results you get.
Jun 4 '07 #4
rishhh
7
As I've used a LEFT JOIN this should return all records from the adjustments table. The following line excludes matching records

AND adjustments.[Counter Party Description] IS NULL

Remove it and see what results you get.

Thanks a lot. It works!! I highly appreciate your help.
Jun 4 '07 #5

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

Similar topics

0
by: leegold2 | last post by:
I tried what's below, seemed OK, so I replaced an "IN" for the "=" in the subquery below because of the subquery's error message. I thought w/"IN" I'd get three (3) records returned as expected....
2
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
2
by: edself | last post by:
Greetings, I am semi-new to Access and have a query question. I presume the solution is easy, but need some help. I have created a database with a Contact table. The contact table contains...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
5
by: Mike MacSween | last post by:
This as the row source for a combo: SELECT qryRole.RoleID, qryRole.Role FROM qryRole WHERE (((qryRole.RoleID) Not In (SELECT RoleID FROM qryRoleEvent INNER JOIN qryEvent ON qryRoleEvent.EventID...
0
by: JT | last post by:
I'm using access 2000 and with assistance thought I had this problem licked. This query works: SELECT Q3.id, Q3.date, Max(Q3.Rank) AS Ninetieth FROM query3 AS Q3 WHERE...
6
by: phillip.s.powell | last post by:
update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id);...
13
by: ThePrinceIsRight | last post by:
I have a problem with using a subquery in MS Access. The purpose of the sub-query is to create a list of people who have had doctor exams in the past 6 months and exclude them from the main query....
3
by: bharadwajrv | last post by:
Hi... i need to know which approach is good in-terms of performance while deleting the records from two tables... Here is my table struct: Master table (table1)...
19
by: zeusspandex | last post by:
Hello everyone i have 3 fields: 1. Code (Mon01, Mon02 etc) 2. Recycling (Check box, yes or no) 3. Tonnage There are over 10,000 records in this table. I am trying to calculate in a query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.