473,396 Members | 2,029 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,396 software developers and data experts.

Set Difference (I think) Join

I needed to get a list of rows from a table that is not present in
another table.

My problem lies in the fact that I only want SOME of the rows in table
2 used in determining existance. This happens because table 2 contains
historical data (based on report date). Table 1 contains my production
list.

I am able to get most of the code done but cannot seem to incorporate
the reportdate column.

Based on the code below my output should be as follows:
ReportDate = '20031229'
Output = 0 rows

ReportDate = '20031230'
Output = DIA, 123456789

ReportDate = anything else
Output = QQQ, abcdefghi
DIA, 123456789

CREATE TABLE [Indices] (
[Symbol] VARCHAR(10),
[Identity] VARCHAR(10)
)

CREATE TABLE [ClearingIndices] (
[ReportDate] DATETIME,
[Symbol] VARCHAR(10),
[Identity] VARCHAR(10)
)
GO

INSERT INTO [Indices] VALUES ('QQQ', '123456789')
INSERT INTO [Indices] VALUES ('DIA', 'abcdefghi')

INSERT INTO [ClearingIndices] VALUES ('20031229', 'QQQ', '123456789')
INSERT INTO [ClearingIndices] VALUES ('20031229', 'DIA', 'abcdefghi')
INSERT INTO [ClearingIndices] VALUES ('20031230', 'QQQ', 'abcdefghi')
GO

SELECT
I.[Symbol], I.[Identity]
FROM
[Indices] I
LEFT OUTER JOIN
ClearingIndices CI
ON
CI.[Symbol] = I.[Symbol]
AND CI.[Identity] = I.[Identity]
WHERE
--CI.[ReportDate] = '20031230'
CI.[Symbol] IS NULL
AND CI.[Identity] IS NULL
Jul 20 '05 #1
1 3185
Unfortunately your required output didn't match your sample data but I think
this is what you are looking for:

SELECT I.symbol, I.[identity]
FROM Indices AS I
LEFT JOIN ClearingIndices AS CI
ON CI.symbol = I.symbol
AND CI.[identity] = I.[identity]
AND CI.reportdate = '20031230'
WHERE CI.symbol IS NULL

Avoid using reserved words like "Identity" as identifiers.

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
8
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
3
by: Beringer | last post by:
I have the following query in Access: SELECT a.interest_parent_id, a.interest_element_id, b.alr_category_id AS interest_category_id, a.allergy_parent_id, a.allergy_element_id, c.alr_category_id...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
7
by: daniel | last post by:
is there any typical usage that shows their difference? thanks daniel
1
by: ehchn1 | last post by:
Hi, Just curious. Would you use ANSI style table joining or the 'old fashion' table joining; especially if performance is the main concern? What I meant is illustrated below: ANSI Style...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
9
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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
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,...

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.