Click here to Skip to main content
16,011,988 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I want to get the maker who sells pc but not laptops the desired output is E,pl refer the attached file for the table structure
VB
product 
maker model type
A     1232  PC
A     1233  PC
A     1276  Printer
A     1298  Laptop
A     1401  Printer
A     1408  Printer
A     1752  Laptop
B     1121  PC
B     1750  Laptop
C     1321  Laptop
D     1288  Printer
D     1433  Printer
E     1260  PC
E     1434  Printer
E     2112  PC
E     2113  PC
Posted
Updated 4-Jun-12 19:02pm
v2
Comments
Sandeep Mewara 5-Jun-12 11:01am    
Homework! No effort.

I think this might be the right solution for you which will give answer as 'E' only

SQL
SELECT     distinct(maker)
FROM         Product
WHERE     type = 'pc'
except

SELECT     distinct(maker)
FROM         product
WHERE     type = 'laptop';


try it and let me know if it works or not.
 
Share this answer
 
as i understand your query write like this
SQL
select distinct E from product where type='PC'
 
Share this answer
 
Comments
Rahul Rajat Singh 5-Jun-12 2:08am    
The result of this would be:
A
B
E
You should use:
SQL
select * from ( select * from Product where type <> 'laptop') as t where t.type = 'pc'
 
Share this answer
 
Comments
Rahul Rajat Singh 5-Jun-12 2:13am    
I am sorry but i dont understand how is this correct. the result for this query is:

A 1232 PC
A 1233 PC
B 1121 PC
E 1260 PC
E 2112 PC
E 2113 PC

I think he need to find the maker who makes PC and not laptops. Is my understanding wrong? I think he want answer to be 'E' in this particular case.
Dear Friend,

Hope this will work.

SQL
Select * from My_Table with (Nolock) where type='PC' and maker not in (Select maker from My_Table with (Nolock) where type='Laptop')


Regards,
AP
 
Share this answer
 
v2
SQL
SELECT * FROM Product WHERE type not in ('Laptop')



Hope this helps , If yes then plz accept and vote the answer. Any queries / questions on this are always welcome.

Thanks & Regards
RDBurmon.Sr.Software Engineer
 
Share this answer
 
Comments
Arunprasath Natarajan 5-Jun-12 1:21am    
Your query will give the data of Maker(D) who sells printer also.
Mehdi Gholam 5-Jun-12 1:22am    
Partially right, see my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900