473,396 Members | 2,099 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.

exclude query

I have 16,000 rows in tblClient and 3000 rows in NewTable.

SELECT tblClient.*
FROM tblClient INNER
JOIN [New Table] ON tblClient.NoDossier <> [New Table].NoDossier

if I use = (equal) instead of <> (exclude), the query returns 3000 rows

when I use <> it returns 160000 rows,
if I try group by, the query bugs

what is my problem
Jul 23 '05 #1
4 5948

To eliminate duplicate rows use:
-------------------------------------------------------

SELECT DISTINCT tblClient.*
FROM tblClient INNER
JOIN [New Table] ON tblClient.NoDossier <> [New Table].NoDossier
To use group by:
---------------------------------------------------------

SELECT DISTINCT tblClient.col1, tblClient.col2, ......
FROM tblClient INNER
JOIN [New Table] ON tblClient.NoDossier <> [New Table].NoDossier
GROUP BY tblClient.col1, tblClient.col2,.......
*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #2


text, ntext or image cannot be selected as distinct

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #3
You should have mentioned that earlier!
*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #4
Fernand St-Georges (fe****************@videotron.ca) writes:
I have 16,000 rows in tblClient and 3000 rows in NewTable.

SELECT tblClient.*
FROM tblClient INNER
JOIN [New Table] ON tblClient.NoDossier <> [New Table].NoDossier

if I use = (equal) instead of <> (exclude), the query returns 3000 rows

when I use <> it returns 160000 rows,
if I try group by, the query bugs

what is my problem


Using <> as a joining operator is very rarely useful. Say that the number
of rows in tblClient is 163 and in [New Table] have 1000 rows. That makes
up for a total of 163000 possisble combinations. You condition filters out
those 3000 where NoDossier are equal.

What you probably want is:

SELECT c.*
FROM tblClient c
WHERE NOT EXISTS (SELECT *
FROM [New Table] n
WHERE c.NoDossier = n.NoDossier)

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #5

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

Similar topics

1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
9
by: paul.jameson | last post by:
I have a simple Access database that stores Karaoke Songlists for my local pub. From this you are able to print out the song lists they use. Up until now, any duplicate songs that appear on say,...
0
by: starman7 | last post by:
i want to exclude email addresses which are in newsletter_email_addresses which also appear in mooky_private.sign_ups.email and mooky.newsletter_opt_outs.email. my query seems to exclude the...
2
by: Arsen V. | last post by:
Hi, How to exclude the App_Data directory from Visual SourceSafe? It appears that Vs 2005 automatically adds the App_Data directory with the large binary MDF and LOG files to the Visual...
4
by: ninrulz | last post by:
I have been working on a database to perform some of the tasks that I have been doing manually in Excel. One of those tasks is to sort and exclude duplicate data. The fields are as follows ...
2
by: Mirnes | last post by:
I have a listbox which is populated from Sql query and I use it to add values to table. I would like to exclude value which just has been added from listbox. Since it is impossible to do in query...
8
by: tonsam | last post by:
I have a report (monthly inventory) whose record source is based on a query named monthly_inventory_qry. On same query (monthly_inventory_qry), I add two fields (month_1 and month_2)and its sum was...
1
by: bips2005 | last post by:
i have got two tables,one customer with fields cust_id,email and another with field cust_id,domname,expirydate. i have this query to combine these two tables to give me email and the expirydate as ...
6
by: Dan2kx | last post by:
Good aft peeps, i have a a working solution for this already but i suppose you could say it is a bit lazy, I have used ADezii's calendar to display dates in my own unique way using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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.