Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 December 2nd, 2004, 06:28 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Basic SQL Problem

Hi,

I have 2 table in my database, all I need to do is select all records from one database that dont exist in the other.

The problem is I get repeating records, can anybody help?

Here is my sql:

SELECT * FROM personaldetails INNER JOIN dbo.ql ON personalDetails.applicationID = dbo.ql.applicationID
WHERE ( personaldetails.applicationid <> ql.applicationid
  ) ORDER BY personaldetails.applicationid DESC

 
Old December 2nd, 2004, 09:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can use the MINUS operator.

SELECT columns_here FROM table_here
MINUS
SELECT columns_here FROM table2_here

Make sure the number and datatypes of the columns in both SELECT statements are identical and the columns in the WHERE clause must be in both SELECT statements.


 
Old December 3rd, 2004, 06:53 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

Hi,

SELECT * FROM PERSONALDETAILS WHERE APPLICATIONID NOT IN
     (SELECT APPLICATIONID FROM ql)

Hope this works.



B. Anant
 
Old December 7th, 2004, 11:35 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to YHAVR
Default

I did this many times to avoid dups when imported data. Try this:

SELECT * FROM personaldetails LEFT JOIN dbo.ql ON personalDetails.applicationID = dbo.ql.applicationID
WHERE ( ql.applicationid IS NULL --MEANING THERE IS NOW MATCHING RECORDS IN ql
  ) ORDER BY personaldetails.applicationid DESC


 
Old December 8th, 2004, 05:20 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all your replys






Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic SQL query john2007 Beginning VB 6 2 January 18th, 2007 04:39 PM
Some basic advice on updating SQL please! garryg ASP.NET 1.0 and 1.1 Basics 3 March 2nd, 2006 02:52 PM
Integrating SQL with visual basic function, how?? Calverstine VB Databases Basics 0 October 23rd, 2005 12:29 AM
SQL and Visual Basic mytreasure23 SQL Server 2000 1 November 9th, 2004 03:26 AM
A Basic SQL Server Question shaked21 SQL Server 2000 9 October 8th, 2003 02:00 AM





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