Try as I might I cannot find a way to write an access query to return a
result set with the records from my database WITHOUT a certain set of
values within a field.
To explain, I have a table of customers linked to a table of customer
contacts. The contact table has a field called 'type of contact'.
Contact types can be numeric 1 to 40 and show the different types of
contact I have with my customers (e.g. 1 - initial contact, 2 -
follow-up, 3 - service call, 4 - customer query etc etc).
All the contacts are recorded in the contact table, so a customer will
have multiple entries in the contact table.
I want a list of customers WITHOUT contact values 30 through 35 to be
shown. However just asking for <30 and >35, returns all customers with
values outside this criteria, i.e. customers with contact types 1-29
and 36-40.
I want to know how to return a list of customers which don't have
contact types 30-35 within the contact type table.
Very many thanks for your help.
Jon 5 2553
could you: first write a query to find all contacts with contact type
30 - 35 and then use the results fo that query as an 'excluding query'
to select all contacts except those in the excluding query?
Alternatively, can you not use OR in the QBE form, that is put "<30 or
>35" in contact type 1, then put "<30 or >35" on the next 'OR' line for contact type 2, etc, etc.
DG.
redstamp wrote:
Try as I might I cannot find a way to write an access query to return a
result set with the records from my database WITHOUT a certain set of
values within a field.
To explain, I have a table of customers linked to a table of customer
contacts. The contact table has a field called 'type of contact'.
Contact types can be numeric 1 to 40 and show the different types of
contact I have with my customers (e.g. 1 - initial contact, 2 -
follow-up, 3 - service call, 4 - customer query etc etc).
All the contacts are recorded in the contact table, so a customer will
have multiple entries in the contact table.
I want a list of customers WITHOUT contact values 30 through 35 to be
shown. However just asking for <30 and >35, returns all customers with
values outside this criteria, i.e. customers with contact types 1-29
and 36-40.
I want to know how to return a list of customers which don't have
contact types 30-35 within the contact type table.
Very many thanks for your help.
Jon
(Untested)
SELECT *
FROM CONTACTS
WHERE CONTACTS.CUSTID NOT IN (
SELECT C2.CUSTID FROM CONTACTS AS C2
WHERE C2.CTYPE BETWEEN 30 AND 35)
;
--
Smartin
Smartin wrote:
redstamp wrote:
Try as I might I cannot find a way to write an access query to return a
result set with the records from my database WITHOUT a certain set of
values within a field.
To explain, I have a table of customers linked to a table of customer
contacts. The contact table has a field called 'type of contact'.
Contact types can be numeric 1 to 40 and show the different types of
contact I have with my customers (e.g. 1 - initial contact, 2 -
follow-up, 3 - service call, 4 - customer query etc etc).
All the contacts are recorded in the contact table, so a customer will
have multiple entries in the contact table.
I want a list of customers WITHOUT contact values 30 through 35 to be
shown. However just asking for <30 and >35, returns all customers with
values outside this criteria, i.e. customers with contact types 1-29
and 36-40.
I want to know how to return a list of customers which don't have
contact types 30-35 within the contact type table.
Very many thanks for your help.
Jon
(Untested)
SELECT *
FROM CONTACTS
WHERE CONTACTS.CUSTID NOT IN (
SELECT C2.CUSTID FROM CONTACTS AS C2
WHERE C2.CTYPE BETWEEN 30 AND 35)
;
--
Smartin
Thanks for that Smartin, just wondered, what this was trying to do, do
I can insert names where appropriate, i.e. what is C2 and don't I need
to pull * from Customer, not Contacts?
Cheers in advance for your help.
Jon.
redstamp wrote:
Smartin wrote:
>redstamp wrote:
>>Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field.
To explain, I have a table of customers linked to a table of customer contacts. The contact table has a field called 'type of contact'. Contact types can be numeric 1 to 40 and show the different types of contact I have with my customers (e.g. 1 - initial contact, 2 - follow-up, 3 - service call, 4 - customer query etc etc).
All the contacts are recorded in the contact table, so a customer will have multiple entries in the contact table.
I want a list of customers WITHOUT contact values 30 through 35 to be shown. However just asking for <30 and >35, returns all customers with values outside this criteria, i.e. customers with contact types 1-29 and 36-40.
I want to know how to return a list of customers which don't have contact types 30-35 within the contact type table.
Very many thanks for your help.
Jon
(Untested)
SELECT * FROM CONTACTS WHERE CONTACTS.CUSTID NOT IN ( SELECT C2.CUSTID FROM CONTACTS AS C2 WHERE C2.CTYPE BETWEEN 30 AND 35) ;
-- Smartin
Thanks for that Smartin, just wondered, what this was trying to do, do
I can insert names where appropriate, i.e. what is C2 and don't I need
to pull * from Customer, not Contacts?
Cheers in advance for your help.
Jon.
My bad, I was returning CONTACTS records, you wanted CUSTOMERS.
SELECT *
FROM CUSTOMERS
WHERE CUSTOMERS.CUSTI D NOT IN (
SELECT C2.CUSTID FROM CONTACTS AS C2
WHERE C2.CTYPE BETWEEN 30 AND 35)
;
what this was trying to do?
As suggested by another poster, the technique to find "What X are not in
Y" is sometimes solved by taking an inverse approach: Determine what X
/are in/ Y, and exclude those from the results.
In this case, the subquery builds a list of CONTACTS who have at least
one contact type between 30 and 35. The outer query says, give me all
the customers that do NOT appear in the subquery.
This sort of thing can also be done using JOINs. I find the subquery to
be easier to read, though IIRC the JOIN construct is more efficient. In
a small table (a few 1000's of rows) my guess is it won't make any
noticeable difference.
What is C2?
C2 is an alias for the CONTACTS table. The alias accomplishes two
things. One, since I chose a very short name it makes it a little easier
to refer to CONTACTS fields. More importantly in the query I posted
first the alias distinguishes between two instances of the CONTACTS
table. For this reason the alias would be required in the first query.
It is optional in the second.
Hope this helps!
--
Smartin
Thank you very much, this was most helpful indeed!
Smartin wrote:
redstamp wrote:
Smartin wrote:
redstamp wrote: Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field.
To explain, I have a table of customers linked to a table of customer contacts. The contact table has a field called 'type of contact'. Contact types can be numeric 1 to 40 and show the different types of contact I have with my customers (e.g. 1 - initial contact, 2 - follow-up, 3 - service call, 4 - customer query etc etc).
All the contacts are recorded in the contact table, so a customer will have multiple entries in the contact table.
I want a list of customers WITHOUT contact values 30 through 35 to be shown. However just asking for <30 and >35, returns all customers with values outside this criteria, i.e. customers with contact types 1-29 and 36-40.
I want to know how to return a list of customers which don't have contact types 30-35 within the contact type table.
Very many thanks for your help.
Jon
(Untested)
SELECT *
FROM CONTACTS
WHERE CONTACTS.CUSTID NOT IN (
SELECT C2.CUSTID FROM CONTACTS AS C2
WHERE C2.CTYPE BETWEEN 30 AND 35)
;
--
Smartin
Thanks for that Smartin, just wondered, what this was trying to do, do
I can insert names where appropriate, i.e. what is C2 and don't I need
to pull * from Customer, not Contacts?
Cheers in advance for your help.
Jon.
My bad, I was returning CONTACTS records, you wanted CUSTOMERS.
SELECT *
FROM CUSTOMERS
WHERE CUSTOMERS.CUSTI D NOT IN (
SELECT C2.CUSTID FROM CONTACTS AS C2
WHERE C2.CTYPE BETWEEN 30 AND 35)
;
what this was trying to do?
As suggested by another poster, the technique to find "What X are not in
Y" is sometimes solved by taking an inverse approach: Determine what X
/are in/ Y, and exclude those from the results.
In this case, the subquery builds a list of CONTACTS who have at least
one contact type between 30 and 35. The outer query says, give me all
the customers that do NOT appear in the subquery.
This sort of thing can also be done using JOINs. I find the subquery to
be easier to read, though IIRC the JOIN construct is more efficient. In
a small table (a few 1000's of rows) my guess is it won't make any
noticeable difference.
What is C2?
C2 is an alias for the CONTACTS table. The alias accomplishes two
things. One, since I chose a very short name it makes it a little easier
to refer to CONTACTS fields. More importantly in the query I posted
first the alias distinguishes between two instances of the CONTACTS
table. For this reason the alias would be required in the first query.
It is optional in the second.
Hope this helps!
--
Smartin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: |
last post by:
If I need to check if a certain value does exist in a field, and return
either "yes" or "not" which query would be the most effestive?
|
by: Brian |
last post by:
I hope this will make sense. I'm trying to filter the records in a
table based on records in a 2nd table. The trick is, I can't use a
query. I'm trying to filter down the number of records going to a
SmartList to go db. The SMtG Access sync will not allow you to sync
to a query based on more than one table. And if I sync all the
records in table 1 (6000)and table 2 (15,000), it take a loooooong
time to sync I've got an easy solution...
|
by: Sreeneet |
last post by:
Hi all,
I want to call a stored procedure which is written in SQL Server from
an ms-access query. It is having some parameters also and the stored
procedure will return some records.
Is there any way to do this?
Any help?
|
by: Simon |
last post by:
Dear reader,
I found out a strange behaviour in a query of the type Total (summation
query).
In case of a normal select query with a criteria setting Is Null for
field-A, four (4) records are found.
|
by: jkuruvil |
last post by:
I need to print a report of a bunch of records that falls between certain dates. Some records have dates and some don't. I did a UNION query to look for everything that falls between these two dates and everything that have NULL in date fields. Records get sorted in an ascending order. So, now I do see all the records, but I like to display records without dates in the end with another title. How could I do this.
| |
by: mrkselm |
last post by:
Hi,
I am stuck with a problem in MS Access which does not occur in SQL
Server and I have been banging my head against the wall for a couple of
days now trying to resolve it. Namely, when I execute the following
query in Access not all records that fit the condition are returned,
and when I run this same query in SQL Server all the records I want are
retrieved.
The query is:
|
by: austin1539 |
last post by:
I am trying to run an Access query from Excel. The query, called "ProdActs1" works in Access and is run from using information from a table called "Queries". When a button is clicked in Excel, data currently in the table is deleted and new data is sent based on cell value on the Excel worksheet. So far, I can delete the old records and add new data. I just cannot seem to return results from the query "ProdActs1". Also, is it possible to specify...
|
by: Comandur |
last post by:
Hi,
I am trying to export an access query to excel. I have made use of transferspreadsheet command to achive this. However i have hardcoded the path and the filename in the VBA code. I am not sure as to how i can make the user enter his ownfile name and select the location where the file is to be written.
I am attaching below my code:
Private Sub Report_Click()
On Error GoTo Err_Report_Click
Dim db As DAO.Database
|
by: jsacrey |
last post by:
Hey everybody, got a secnario for ya that I need a bit of help with.
Access 97 using linked tables from an SQL Server 2000 machine.
I've created a simple query using two tables joined by one field
between them. The join field in both tables are indexed and I'm
selecting 1 field from each table to lookup. The Access query is
taking more than 60 second to retrieve 1 record and if I execute the
same query within the Query Analyzer, it...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |