adspace
Please give me queries for the following
1. To get the count of duplicate records.
2. A query to delete the duplicate records.
Answer Posted / meher
1. To get the duplicate records.
Use group by clause to the column on which you want to
check the duplicates records.
syntax:
select column_name, count(*) from table_name group by
column_name having count(*) >1
2. To delete the duplicate records.
syntax:
delete from table_name where rowid in (select max(rowid)
from table_name group by column_name having count(*)>1 )
This will work.
Please let me know in case of any issues.
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
explain different types of backups avaialabe in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration
What are the source of constraints?
This question asked during interview, 2) At the end of each month, a new table is created for each bank that contains monthly metrics consolidated at the account level. The table naming convention is bankX_YYYYMM where X represents the numeric designation of the bank and YYYYMM indicates the 4 digit year and 2 digit month. The tables contain the following fields: name data type description account text account number registered boolean indicates whether the account is registered num_trans integer number of transactions made during the time period spend numeric(9,2) total spend during the time period a) Write a SQL query that will display the total number of transactions and total spend for "Bank1" during the 4th quarter of 2009. b) Write a SQL query that will display the total number of transactions and total spend at "Bank1" and "Bank2", broken out by registered vs. non-registered accounts, during January 2010 not sure what is correct answer and how to solve?
what is the difference between openrowset and openquery?
How to convert character strings into numeric values?
What is the difference between upgrade and migration in sql server?
How do I create a trace in sql server?
How to remove duplicate rows from table except one?
Explain system functions or built-in functions? What are different types of system functions?
What is acid mean in sql server?
what is spatial nonclustered index
What is standby servers? Explain types of standby servers.
How do I start sql server 2017?
Explain “row_number()” in sql server with an example?
Disadvantages of the indexes?