Hello,
I am new to SQL server and I struggle a little with something, maybe is very easy but i just can't solve it. I have some countries with stores. This is my example table:
create table my_table
(
[ID] [nvarchar]2 NULL,
[Country] [nvarchar]20 NULL,
[Markets] [nvarchar]50 NULL
)
insert into my_table(ID,Country,Markets)
values('AL', 'Albania','C&A')
values('AL', 'Albania','Douglas')
values('AL', 'Albania','')
values('AD','Andorra','C&A')
values('AD','Andorra','')
values('EE','Estonia','Sephora')
values('EE','Estonia','Douglas')
values('EE','Estonia','')
I only need to extract the countries that have only C&A and blancks in the Market column.
In may case is only Andorra. Even if Albania has C&A and blanck , it also have Douglas and thats why i dont need that country.
my code is:
select distinct ID into #table1 from my_table
where Markets='C&A'
select * into #table2 from my_table
where [ID] in (select distinct [ID] from #table1 )
I know the mistake because it takes also Albania, not only Andorra because of the #table1
I cant figre it out how to substarct only the country with only C&A and blancks thats all.
I would appreciate any help if its possible
Thank you in advance!