SQL, How to wirte the condition

Hi Expert,

In my query below, Dealerid A has 2 sponsors: atc and dws. Dealerid B has only 1 sponsor: atc.
I want to get the dealerid B ONLY.
But the query I wrote below return dealerid A and B to me. I could not recall which query code I should use to get the dealerId WHO HAS 'DWS' ONLY

Thanks,

select dealerid,sponsor
from [MakeMyDeal_com].[dbo].[adobe_Standard]
where sponsor <> 'ATC'
tanj1035Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
select dealerid,sponsor
from [MakeMyDeal_com].[dbo].[adobe_Standard]
where sponsor in ('atc', 'dws')

Open in new window

0
tanj1035Author Commented:
Sorry, I did not explain it clearly. I just want to get the dealerid whose sponsor is 'DWS' only.
0
Kanti PrasadCommented:
elect dealerid,sponsor
from [MakeMyDeal_com].[dbo].[adobe_Standard]
where sponsor = 'DWS'
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Reza RadConsultant, TrainerCommented:
select * from <yourtable> where dealerid not in 
(select distinct dealerid from <yourtable>
where sponsor<>'DWS')
and sponsor='DWS'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
select dealerid, sponsor, count(sponsor)
from [MakeMyDeal_com].[dbo].[adobe_Standard]
where sponsor = 'DWS'
group by dealerid, sponsor
having count(sponsor)=1

Open in new window

0
PortletPaulfreelancerCommented:
The best method for asking this type of question is to supply both "sample data" and the "expected result"

This is the data you suggested (but this is a better way of presenting it):

CREATE TABLE adobe_Standard
    ([id] int, [dealerid] varchar(1), [sponsor] varchar(3))
;
   
INSERT INTO adobe_Standard
    ([id], [dealerid], [sponsor])
VALUES
    (1, 'A', 'atc'),
    (2, 'A', 'dws'),
    (3, 'B', 'atc')
;


But what is the "expected result"?


Note:
From the description in your question, I don't think you have a sample of data with a dealerid that has 'dws' only.

If I add another row (ID=4) is that a  dealerid has 'dws' only ?

INSERT INTO adobe_Standard
    ([id], [dealerid], [sponsor])
VALUES
    (1, 'A', 'atc'),
    (2, 'A', 'dws'),
    (3, 'B', 'atc'),
   (4, 'C', 'dws')
;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.