开发者

SQL Show duplicate records only once in a result set

Is it possible in SQL to show duplicate records in a result only once.

So instead of this

         my@email.com | Some Unique Data | Unique Data

         my@email.com | Some Unique Data | Unique Data

         my@email.com | Some Unique Data | Unique Data

         my@email.com | Some Unique Data | Unique Data

I would get this

      开发者_StackOverflow社区   my@email.com | Some Unique Data | Unique Data

                      | Some Unique Data | Unique Data

                      | Some Unique Data | Unique Data


You should not be using SQL to perform presentational tasks. Any solution to do so is going to be very hacky and require cursors / some other iterative approach.

Almost every report authoring tool has a way to hide duplicates.


simply you can do this --

there are so many option or answer available for this. one of these is as follow--

select 
case 
when b.c_1 = 1 then 
b.col1
else
null
end col1,
b.col2 col2,
b.col3 col3
from
(
select distinct col1,col2,col3, rownum() over(partition by col1) c_1 from table_name
)b

now assume / modify above query -

table_name is the table name col1 , col2 and col3 is your table's column name.

just modify this query as per your table name and structure and see..

it would be your required solution.


I know that this is an old question but thought this might be of use to other people. After researching this for awhile, there is a keyword called DISTINCT that will show duplicate values in a query only once. I was using a query to auto-suggest values in a text box on a web page and didn't want it to show duplicate names and this worked for me:

  SELECT DISTINCT FIRSTNAME
  FROM TBLSTUDENTS
  WHERE FIRSTNAME LIKE '#ucase(arguments.search)#%'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜