CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies

Search Interview Questions

Question: How to delete same id in rows?
For example empid=5 repeated for times in rows. How to delete which sql query is used?

Answer: we can use distinct clause for this type of query.distinct clause is used to remove duplicates from table
like
select rowid distinct from table name



Category SQL Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.5) By 667 users
Added on 9/12/2012
Views 9010
Rate it!
Question: How to delete same id in rows?
For example empid=5 repeated for times in rows. How to delete which sql query is used?

Answer:

we can use distinct clause for this type of query.distinct clause is used to remove duplicates from table
like
select rowid distinct from table name
Source: CoolInterview.com

Answered by: nidhi | Date: 10/10/2007 | Contact nidhi Contact nidhi

To find out duplicate rows in a table write the following query.

select column1,count(column1) from table1 group by column1 having count(column1)>1 Source: CoolInterview.com

Answered by: Raja Mukherjee | Date: 10/15/2007 | Contact Raja Mukherjee Contact Raja Mukherjee

delete from emp where rowid not in(select min(rowid)from emp group by empno); Source: CoolInterview.com

Answered by: Kulminder Singh | Date: 10/19/2007 | Contact Kulminder Singh Contact Kulminder Singh

rowid is not valid for sql server query. Source: CoolInterview.com

Answered by: Raja Mukherjee | Date: 10/22/2007 | Contact Raja Mukherjee Contact Raja Mukherjee

The rowid is unique for the each table.
so the row id is not repeated in table.
Each row has a unique rowid.We can delete each & every row using rowid.Sometime the empid is not introduced primary key we can delete the same records in table. Source: CoolInterview.com

Answered by: nisha | Date: 11/28/2007 | Contact nisha Contact nisha

delete * from tablename where empid=5; Source: CoolInterview.com

Answered by: Monika | Date: 1/14/2008 | Contact Monika Contact Monika

delete from table-name where empid=5 Source: CoolInterview.com

Answered by: praveen | Date: 1/24/2008 | Contact praveen Contact praveen

sql> select distinct * from emp;

The above query will avoid the duplicate records froom the table and will dispaly the unique records. But remember it will not delete the duplicate record it will just filter the unique r display.

select column1,count(column1) from table1 group by column1 having count(column1)>1

The above query will just dispaly the records repeted in times.

SQL> delete emp where rowid not in(select min(rowid) from emp group by name);

3 rows deleted.

the above is query to delete the duplicate records from the table. After executing the above command if will run the below query
sql> select * from emp;
The above query will display the unique records only as there is no duplicate records exeisting in table. Source: CoolInterview.com

Answered by: Satyam | Date: 5/15/2008 | Contact Satyam Contact Satyam

Sql> delete emp where rowid not in(select min(rowid) from emp group by columnname);
The above query will delete the all duplicate record. If we want to delete the particular duplicate records from the table we can fire the below query as an example
Sql> delete emp where rowid in( select min(rowid0 from emp where name=?satyam?);

Source: CoolInterview.com

Answered by: Satyam | Date: 5/15/2008 | Contact Satyam Contact Satyam

WITH Emp AS (SELECT ROW_NUMBER ( ) OVER ( PARTITION BY EmpID, EmpName ORDER BY EmpID ) AS RNUM FROM #Test )
DELETE FROM Emp WHERE RNUM > 1 Source: CoolInterview.com

Answered by: sagar | Date: 2/20/2009 | Contact sagar Contact sagar

delete from emp where emp_id = 5 and emp_id in (select emp_id from emp group by emp_id having count(emp_id)>1); Source: CoolInterview.com

Answered by: Preeti lamba | Date: 11/1/2009 | Contact Preeti lamba Contact Preeti lamba

delete from emp
where rowid not in (select max(rowid)
from emp
group by name);

the above query deletes the duplicate records. For example in the employee table name 'XYZ' is repeated 3 times, above query deletes 2 records with name 'XYZ'. Source: CoolInterview.com

Answered by: Kiran Vangeti | Date: 3/19/2010 | Contact Kiran Vangeti Contact Kiran Vangeti

create table t1(col1 int, col2 int, col3 char(50))
insert into t1 values (1, 1, 'data value one')
insert into t1 values (1, 1, 'data value one')
insert into t1 values (1, 2, 'data value two')


SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1

set rowcount 1
delete from t1
where where col1=1 and col2=1 Source: CoolInterview.com

Answered by: Srimanta | Date: 3/26/2010 | Contact Srimanta Contact Srimanta

delete from table where empid in(select empid from table group by empid having (count*)>1); Source: CoolInterview.com

Answered by: hussain reddy | Date: 4/30/2010 | Contact hussain reddy Contact hussain reddy

For example:--

SELECT DISTINCT sysdate FROM emp;

Answer is :-- 17-AUG-2010

Or,.....

SELECT DISTINCT deptno from emp;

Answer:-- DEPTNO

10
20
30 Source: CoolInterview.com

Answered by: Rameshwar Nath Show | Date: 8/17/2010 | Contact Rameshwar Nath Show Contact Rameshwar Nath Show

delete from emp where eid in(select eid from emp group be eid having count(eid)>1) Source: CoolInterview.com

Answered by: saisowhit | Date: 5/17/2016 | Contact saisowhit Contact saisowhit


If you have the better answer, then send it to us. We will display your answer after the approval

Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.

Post your answer here

Inform me about updated answers to this question.
Related Questions
View Answer
Difference between decode and case.
in which case we are using case and in which case we are using decode?
with an example.

View Answer
How to retrieving the data from 11th column to n th column in a table.

View Answer
what is the difference between oracle,sql and sql server

View Answer
on index
why u need indexing ? where that is stroed
and what u mean by schema object?
for what purpose we are using view

View Answer
I have a table with duplicate names in it. Write me a query which returns only duplicate rows with number of times they are repeated.

View Answer
Difference between Stored Procedure and Trigger

View Answer
When using a count(disitnct) is it better to use a self-join or temp table to find redundant data, and provide an example?

View Answer
What is the advantage to use trigger in your PL?

View Answer
What the difference between UNION and UNIONALL?

View Answer
How to find second maximum value from a table?

View Answer
How to display duplicate rows in a table?

View Answer
What is joint?

View Answer
What is the difference between TRUNCATE and DELETE commands
View Answer
Which system table contains information on constraints on all the tables created?
View Answer
Which command displays the SQL command in the SQL buffer, and then executes it
View Answer
What does the following query do



View Answer
What will be the output of the following query

View Answer
TRUNCATE TABLE EMP;

DELETE FROM EMP;

Will the outputs of the above two commands differ


View Answer
What is the difference between Single row sub-Query and Scalar sub-Query

View Answer
How do I write a cron which will run a SQL query and mail the results to a group?

View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All SQL Interview Questions & Answers - Exam Mode / Learning Mode




India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 3.140625 Seconds