user204588
user204588

Reputation: 1633

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

         [email protected] | Some Unique Data | Unique Data

         [email protected] | Some Unique Data | Unique Data

         [email protected] | Some Unique Data | Unique Data

         [email protected] | Some Unique Data | Unique Data

I would get this

         [email protected] | Some Unique Data | Unique Data

                      | Some Unique Data | Unique Data

                      | Some Unique Data | Unique Data

Upvotes: 1

Views: 8308

Answers (3)

trueinViso
trueinViso

Reputation: 1394

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)#%'

Upvotes: 1

pratik garg
pratik garg

Reputation: 3342

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.

Upvotes: 1

Yuck
Yuck

Reputation: 50845

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.

Upvotes: 8

Related Questions