Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 SQL .NET , +
I have a table and records as like this:
Table name: tbl_post
Columns: Id, Title,ep
 
records in the table:
Id  Title     Ep
1   Horror    4
2   Reality   6
3   Sci-Fi    3
4   Horror    7
5   Romance   8
6   Horror    2
and so on...
I just want to show it as
Id  Title     Ep
1   Horror    4
2   Reality   6
3   Sci-Fi    3
5   Romance   8
and so on (eliminating all the other repeating title)
 
I have tried distinct but no use.
Please suggest me some queries (ms-sql)
Posted 22-Apr-13 21:56pm
ujju.15K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
Try this...
with Post 
AS
(
  SELECT Id, Title,ep,  
     row_number() over (partition by Title order by Id) as rowid
  from tbl_post
)
SELECT *
FROM Post where rowid = 1;
Regards,
GVPrabu
  Permalink  
v2
Comments
ujju.1 at 23-Apr-13 4:00am
   
its showing error: "Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Id'.
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'SELECT'."
 
But might work with some modifications...will try.
ujju.1 at 23-Apr-13 4:13am
   
thanx gvpravu...got it what i wanted
 
with Post
AS
(
SELECT Id, Title,ep,
row_number() over (partition by Title order by Id) as rowid
from tbl_post
)
SELECT *
FROM Post where rowid = 1;
gvprabu at 23-Apr-13 4:22am
   
Hi,
In my machine I don't have SQL Server So I used Note pad for Frame this Query... Okie fine If u got the logic thats enof. have a nice day
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Select * From tbl_post Where Title in(Select Distinct(Title) From tbl_post )
  Permalink  
Comments
ujju.1 at 23-Apr-13 3:14am
   
Not working dear. The query will match with repeating titles also and show all the records.

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100