Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sql query selct statement

Posted on 2010-11-19
9
426 Views
Last Modified: 2012-05-10
Hi,

I have a table with customer number and memo types left on their account.
e.g.

---------------------------
Customermemo
---------------------------
cnum     memotype
a1               debt
b1                good
a1                paid
b1                debt
b3                new
b2                leaving
b2                left
b3                paid

I have another table with only customer number
----------------
Customer
------------------
customerno
a1
b1
a2
b2
b3
a3

Now i am trying to get distinct customer number without memotype debt ( that customer number should be in both tables)

here is a query

select distinct(cnum) from customermemo, customer where
memotype <> 'DEBT'
and
cnum = customerno

But still i kept on getting a1 in the output though i do not want anything with the memo type DEBT.
0
Comment
Question by:santoshmotwani
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 34176839
try the updated below:

select distinct(cnum) from customermemo cm, customer c
where ltrim(rtrim(cm.memotype)) <> 'DEBT' and cm.cnum = c.customerno
0
 
LVL 39

Expert Comment

by:lcohan
ID: 34176855
even better as you may have a case sensitive database and "debt" <> "DEBT"

select distinct(cnum) from customermemo cm, customer c
where upper(ltrim(rtrim(cm.memotype))) <> 'DEBT' and cm.cnum = c.customerno
0
 
LVL 32

Accepted Solution

by:
ewangoya earned 250 total points
ID: 34177030
select distinct(cnum)
from customermemo
inner join customer on customer.customerno = customermemo.cnum
where ltrim(rtrim(memotype)) <> 'debt
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 40

Expert Comment

by:Sharath
ID: 34177297
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34177312
Yes.  What is great is when you see the same solution copied and pasted in both questions.  Can you say wishful thinking?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34177331
I have posted a message in CS.  More than likely points will be halved in both questions.
0
 
LVL 16

Author Comment

by:santoshmotwani
ID: 34177472
i apologize for posting it twice .
0
 
LVL 16

Author Closing Comment

by:santoshmotwani
ID: 34185643
Thnx !!! that helped
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question