Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2004, 12:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default Help with SQL statement

Hi

I need some help with a query/logic. I have created a program that log email rountrip time. I have got 2 Tables. The first table in inbox and the second Sent Items.

Inbox
***** Fields
Subject|Received
******
Sent Items
*****Fields
Subject|Sent
******

Subject will be the same for the mail that has been sent and the mail returned.

If I use the following it returns only mail that has been sent and received.

SELECT Inbox.Subject, Inbox.Received, [Sent Items].Sent
FROM Inbox INNER JOIN [Sent Items] ON Inbox.Subject = [Sent Items].Subject
ORDER BY Inbox.Subject

How could I query this to determine if a subject line exist in Sent Items but not in Inbox---to indicate it never came back? (More of a comparison between the tables)

Any advice/help appreciated

Regards
Marnus
 
Old June 17th, 2004, 12:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Not sure if you are using MSACCESS or SQL Server.

You can use this.

SELECT [Sent Items].Subject, [Sent Items].Sent
FROM [Sent Items], Inbox WHERE [Sent Items].Subject <> Inbox.Subject
ORDER BY [Sent Items].Subject

Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 18th, 2004, 03:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Or you could use a LEFT JOIN, this way all email's that never came back will have NULL in the [Sent Items].Sent column. Here is an example:
Code:
  SELECT Inbox.Subject, Inbox.Received, [Sent Items].Sent
    FROM Inbox LEFT JOIN [Sent Items] ON Inbox.Subject = [Sent Items].Subject
ORDER BY Inbox.Subject
I hope this helps.

Regards
Owain Williams
 
Old June 18th, 2004, 04:53 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

Thanks, I will give this a shot...

Marnus





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with SQL Statement forumsUID SQL Server 2000 1 August 23rd, 2007 08:08 AM
convert a SQL Statement from MS Access to a SQL Corey Access 6 March 28th, 2007 12:33 PM
SQL Statement rylemer SQL Language 3 October 21st, 2005 09:07 PM
Sql Statement help morpheus Classic ASP Basics 0 March 9th, 2004 10:55 AM
sql statement chrisangus@btinternet.com Beginning VB 6 2 June 23rd, 2003 04:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.