Click here to Skip to main content
15,887,326 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more: , +
I have a table and records as like this:
Table name: tbl_post
Columns: Id, Title,ep

records in the table:
SQL
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
SQL
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

Hi,

Try this...
SQL
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
 
Share this answer
 
v2
Comments
ujju.1 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 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 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
Select * From tbl_post Where Title in(Select Distinct(Title) From tbl_post )
 
Share this answer
 
Comments
ujju.1 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)



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