SQL Server - need help with the query - Asked By abinav shankar on 05-Jun-12 12:45 AM

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

product



S K replied to abinav shankar on 05-Jun-12 12:49 AM
Simply use this query

Select * from tblanme where type = 'PC' AND type <> 'laptop'

above query gives you your desired result E
S K replied to abinav shankar on 05-Jun-12 12:50 AM
if you want to get only type E as output
simply modify my above query as 

Select distinct type from tblanme where type = 'PC' AND type <> 'laptop' 
TSN ... replied to abinav shankar on 05-Jun-12 12:52 AM

HI…
here is the Query

 

Select maker from table where type = 'PC' AND type != 'Laptop'

abinav shankar replied to TSN ... on 05-Jun-12 12:56 AM
hi

if you use that it will give you A,B,E as the output
abinav shankar replied to S K on 05-Jun-12 12:56 AM
hi

if you use that it will give you A,B,E as the output
abinav shankar replied to S K on 05-Jun-12 12:57 AM
hi

if you use that it will give you A,B,E as the output
Jitendra Faye replied to abinav shankar on 05-Jun-12 12:59 AM
Use this command-


Select * from tablename where type = 'PC' AND type <> 'Laptop'
Jitendra Faye replied to abinav shankar on 05-Jun-12 01:00 AM
If you want only E record then use this query-

Select * from tablename where type = 'PC' AND type <> 'Laptop' AND marker='E'
TSN ... replied to abinav shankar on 05-Jun-12 01:12 AM

Hi..

In that case use a SubQuery which will first eliminate the Makers who sell the Laptops and then you can get the maker of Only PC’s

Here Is the Query

 

Select maker from tblanme where type = 'PC' AND maker not in (select Maker from tableName Where type=’Laptop’

Ping back if any issues

abinav shankar replied to Jitendra Faye on 05-Jun-12 01:13 AM
Hi vicky

your query produced correct result but cannot hard code maker as E directly
Jitendra Faye replied to abinav shankar on 05-Jun-12 01:16 AM
Hi Abhinav,

Actually there is no particular condition to get your desired result, there are 2 possible ways-

1-

Select * from tablename where type = 'PC' AND type <> 'Laptop' AND marker='E'

2-

Select * from tablename where type = 'PC' AND type <> 'Laptop' AND marker not in ('A','B','C','D')


You need to hard code only