SunQuest
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 20th, 2004, 10:46 AM
paneolo paneolo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 paneolo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MS Access Query Help

I am trying to find all records where certain fields match AND one field doesn't.

I have the following fields in the table 'customers':
Company, FirstName, LastName, CustomerNumber

I want to be able to find all records where FirstName and LastName are the same but CustomerNumber is not.

I've had success getting all records where FirstName and LastName are the same but don't know how to add the last condition. Any help would be greatly appreciated!

Paneolo

Reply With Quote
  #2  
Old April 22nd, 2004, 11:21 AM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
I'm not clear on what you're asking...I assume you're loooking for solution for this...

Let's take record A and record B, you want to return where recordA.lastname = recordB.lastname AND recordA.firstname = recordB.firstname AND recordA.CustomerNumber <> to recordB.CustomerNumber?? Is that right?

Reply With Quote
  #3  
Old April 22nd, 2004, 11:26 AM
paneolo paneolo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 paneolo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes, that is exactly what I'm trying to do.

Reply With Quote
  #4  
Old April 22nd, 2004, 11:38 AM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
IF the customer ID is the primary key and always unique, this will work...know that for both examples, the count on CustomerNumber (in the SELECT) isn't necessary, just thought I'd throw it in.

This will find the people that fit the criteria...
Code:
Select C.lastname, C.firstname, count(C.CustomerNumber) as countCustNum
from   tblCustomers C
group  by C.lastname, C.firstname
having count(C.CustomerNumber) > 1;

...if you still need to go back and return all the fields in the table, join the above query back to the Customers table...
Code:
Select  * from Customers C
inner   join
        (Select  C.lastname, C.firstname,
                 count(C.CustomerNumber) as countCustNum
         from    tblCustomers C
         group   by C.lastname, C1.firstname
         having  count(C.customerNumber) > 1) as A
on       C.Lastname = A.lastname
and      C.firstname = A.firstname;


...is the CustomerID in fact a unique value in all the records?

Last edited by Username=NULL : April 23rd, 2004 at 03:21 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > MS Access Query Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway