Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL query help

Author  Topic 

drpkrupa
Yak Posting Veteran

74 Posts

Posted - 2010-06-15 : 12:31:20
I have table which has three column.

select '1995' as year, cast('Toyota' as varchar(50)) as mke, cast('Carola' as varchar(50)) as model
into #tmp
union all
select '1995' as year, cast('Toyota' as varchar(50)) as mke, cast('Carola' as varchar(50)) as model
union all
select '1995' as year, cast('Toyota' as varchar(50)) as mke, cast('Camerry' as varchar(50)) as model
union all
select '1996' as year, cast('Toyota' as varchar(50)) as mke, cast('Truck' as varchar(50)) as model
union all
select '1996' as year, cast('Toyota' as varchar(50)) as mke, cast('Truck' as varchar(50)) as model
union all
select '1996' as year, cast('Honda' as varchar(50)) as mke, cast('Civic' as varchar(50)) as model


I want to write query which give me only following two rows.

select '1996' as year, cast('Honda' as varchar(50)) as mke, cast('Civic' as varchar(50)) as model

and
select '1996' as year, cast('Toyota' as varchar(50)) as mke, cast('Truck' as varchar(50)) as model


these are only two model that issued on specific year by specific make.

It measn i need all model that only issue by make for that year.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-15 : 12:33:43
select * from #tmp where year = '1996'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-16 : 02:53:31
If you dont want duplicates, use distinct

select distinct * from #tmp where year = '1996'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -