Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with select statement 1

Status
Not open for further replies.

wysiwygger

Programmer
Jun 20, 2006
78
AU
Hi,

I've got the following SQL statement and it is working almost fine.

select distinct cscontact.name, relkeyword.swcode from cscontact,relkeyword where cscontact.pubindex = relkeyword.relpubindex(+) AND (relkeyword.swcode <> 173 OR relkeyword.swcode IS NULL) order by cscontact.name

The statement returns all contacts which have no keyword 173 or no keyword at all assigned to it.
Unfortunately the table relkeyword has more then 1 entry for the same contact person.

1 person might have an entry with keyword 173 and another one with keyword 99.
Currently the entry with keyword 173 is left out but it still shows the line with keyword 99.

I want to leave out a contact completely as soon as it has keyword 173 assigned to it.
Any ideas on how to achieve that would be much appreciated.
 
At times I feel like the world's number one advocate of analytic functions, since I seem to suggest them as a solution for virtually every problem. However, I do find them incredibly useful and think they can come up trumps for this one as well.

Code:
select distinct name, swcode 
from 
(select cscontact, relkeyword, swcode,
count(case when relkeyword.swcode = 173 then 1 end) over (partition by cscontact.name) as cnt173
from cscontact,relkeyword 
where cscontact.pubindex = relkeyword.relpubindex(+))
where cnt173 = 0
order by name
 
Thanks Dagon!!!

After changing the second select, your statement runs fine. Excellent!

select distinct name, swcode
from
(select name, swcode,
count(case when relkeyword.swcode = 173 then 1 end) over (partition by cscontact.name) as cnt173
from cscontact,relkeyword
where cscontact.pubindex = relkeyword.relpubindex(+))
where cnt173 = 0
order by name
 
WYSIWYG-ger said:
Thanks Dagon!!!...your statement runs fine. Excellent!
I'm certain that Dagon appreciates your "Thanks", but I've noticed that during your 2 1/2 years as a member of Tek-Tips and your two dozen threads for which you have asked for help from Tek-Tipsters, you have apparently not found the button at the lower left of each reply that says:
star.gif
Thank <helper's name>
for this valuable post!
So, a deserved
star.gif

is the "currency" by which we tender our "Thanks" here at Tek-Tips for a job well done.

Dagon certainly deserves a
star.gif
for his excellent illustration of Oracle's Analytic Functions.

Please click on the screen button that gives a
star.gif
to Dagon.


[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Dagon,

Apparently awarding well-deserved
star.gif
s, even after a gentle reminder from others, is not in wysiwygger's code of ethics, so please accept one from me in recognition of your continued excellence in your responses.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top