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
 Select Statement in sql !

Author  Topic 

pamyral_279
Posting Yak Master

143 Posts

Posted - 2006-04-03 : 06:14:07
I have a problem ? Any suggestions would be appreciated !
I have the following table with structures:

ID Title Character PostDate
1 Tit1 A 20060203
2 Tit2 B 20060201
3 Tit3 C 20060205
4 Tit4 D 20060209
5 Tit5 D 20060202
6 Tit6 A 20060109
7 Tit7 Y 20060801
8 Tit8 B 20060801
9 Tit9 Y 20060801
10 Tit10 Z 20060801
.....
n ... Z 20060801


My problems :
I only want to select some of records with Character= A,B,C,D,E .. Z
and order by PostDate
The output :
1 Tit1 A 20060203
2 Tit2 B 20060201
3 Tit3 C 20060205
4 Tit4 D 20060209
.....
N TitN Z .......

The "Character" Field with A To Z and not repeated !
This means I only want to 26 records.
Any One help me !!
Thank you very much.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-03 : 06:24:55
[code]select t.*
from (
select Character, min(ID) as min_id
from table1
group by Character
) d
inner join table1 t
on d.Character = t.Character
and d.min_id = t.ID[/code]



KH

Choice is an illusion, created between those with power, and those without.
Go to Top of Page

pamyral_279
Posting Yak Master

143 Posts

Posted - 2006-04-03 : 06:55:43
quote:
Originally posted by khtan

select 	t.*
from (
select Character, min(ID) as min_id
from table1
group by Character
) d
inner join table1 t
on d.Character = t.Character
and d.min_id = t.ID




KH

Choice is an illusion, created between those with power, and those without.



Good Job !!
Thank you very much !
Go to Top of Page
   

- Advertisement -