Write a single SQL to delete duplicate records from the a
single table based on a column value. I need only Unique
records at the end of the Query.
Answers were Sorted based on User's Feedback
Answer / nunna
Query to find duplicates in a table:(Custname, Prod,
Order_amt)
select custname,count(*) from sales1 a where a.rowid > ANY
(select b.rowid from sales1 b where a.custname=b.custname
and a.prod=b.prod and a.order_amt=b.order_amt) group by
custname;
Query to delete duplicates:
delete from sales1 a where a.rowid > ANY (select b.rowid
from sales1 b where a.custname=b.custname and a.prod=b.prod
and a.order_amt=b.order_amt);
| Is This Answer Correct ? | 7 Yes | 15 No |
Answer / manny
One need have atleast a unique column such as timestamp col
(and assumption is to keep lowest tmpstmp) OR some key col
say IPID (again keep lowest value)..
One determined - Have a nested Select on all rows (except
that key col) with group by rest of the columns + having
count(*) > 0 + aggreate MIN(key_col).
Now said that, have another outer SEL on all columsn &
do a inner join with above nested Sel .. WHERE outer
key_col <> MIN value of nested SEL..
See if it works..
| Is This Answer Correct ? | 5 Yes | 16 No |
Answer / milind
Nested query method might be required in other databases
how ever in TD we don’t need to follow such a difficult way
to just find out the unique rows.
In TD we have functions like Rank () and Rownum() in the
combination of Qualify, helps you to select out the rows
which you wants to delete.
you can add a condition like ‘Where Rank() > 1’
| Is This Answer Correct ? | 3 Yes | 16 No |
TCS recently asked this question I have records like below Emp id Empname Salary DateTimestamp 1 AA 6000 20120609:11:30 1 AA 7000 20120609:12:30 1 AA 8000 20120609:01:30 I want to exceute records max timestamp(20120609:01:30)
write lock is compatiable with which type of lock?
What does sleep function does in fast load?
why use references rather than pointers in the public api, particularly for arguments which are modified?
1. generally how many node system will be used by the client. 2. while running mload if the job is aborted/failed at any phase what we have to look after to run the job successfully? 3.i wanted to know how to write the fastload script for table creation as well as table loading in a single script?
In which scenarios we use Volatile tables and Global temporary Tables in Real time? Please give me one real time scenario???I know wat is its use??
How to explain project Architecture and flow in teradata interviews?Can please anyone help on this? Am new to teradata.
0 Answers Infosys, Wells Fargo,
Can we have an unconnected lkp to lookup a db2 record against a teradata record? Doesnt seem to work. I could be wrong
can we load 10 millions of records into target table by using tpump?
what is identity column in TD?
What are the different table types that are supported by teradata?
What are the steps involved in the process flow of the sql statement through channel attached system?