GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Database  >  MYSQL
Next Question 
 MYSQL  |  Question 1 of 45    Print  
How we can count duplicate entry in particular table against Primary Key ? What are constraints?

  
Total Answers and Comments: 16 Last Update: February 14, 2008     Asked by: deepti kr misra 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
March 01, 2006 04:49:39   #1  
rajendar Member Since: March 2006   Contribution: 1    

RE: How we can count duplicate entery in particular ta...

select count(*) from tablename where count(*) >1  group by empno;

( jst checkin for to count duplicate records if not  jst send reply to me)

thanx


 
Is this answer useful? Yes | No
March 17, 2006 06:51:28   #2  
bhanu pratap kedia        

RE: How we can count duplicate entery in particular ta...
i want to know how u will find primary key in duplicate data .can we find a primary key in duplicate data.....
 
Is this answer useful? Yes | No
March 19, 2006 09:03:32   #3  
culver_lake        

RE: How we can count duplicate entery in particular ta...
Every table should have a primary key defined. If that is the case the RDBMS will not allow a duplicate row to be inserted. The INSERT statement will fail and the table will never have a duplicate (neither will the unique index).
 
Is this answer useful? Yes | No
March 19, 2006 19:38:39   #4  
Culver_lake Member Since: March 2006   Contribution: 46    

RE: How we can count duplicate entery in particular ta...

The syntax in the previous answer (where count(*) > 1) is very questionable. suppose you think that you have duplicate employee numbers. there's no need to count them to find out which values were duplicate but the followin SQL will show only the empnos that are duplicate and how many exist in the table:

Select empno, count(*)

from    employee

group by empno

having count(*) > 1

Generally speaking aggregate functions (count, sum, avg etc.) go in the HAVING clause. I know some systems allow them in the WHERE clause but you must be very careful in interpreting the result.  WHERE COUNT(*) > 1 will absolutely NOT work in DB2 or ORACLE.  Sybase and SQLServer is a different animal.


 
Is this answer useful? Yes | No
August 23, 2006 03:54:38   #5  
veena        

RE: How we can count duplicate entery in particular ta...

The soln given does not seem to work,

error says group function not allowed in where clause


 
Is this answer useful? Yes | No
August 25, 2006 08:33:51   #6  
Ed DiGiambattista        

RE: How we can count duplicate entery in particular ta...

That's exactly what I said. You can't have any aggregate function in a where clause. They must be in a having clause prededed by group by.

The approach is wrong anyway.

Select empno

from   emp

group by empno

having count(*) > 1


 
Is this answer useful? Yes | No
September 06, 2006 02:18:23   #7  
Mukesh        

RE: How we can count duplicate entery in particular ta...
select count(*) from tablename where count(*) >1 group by empno;this query generate an error use right syntex groupbyI have a table name -> empfields -> id (int autoincremented),name (varchar),sal(int)used query ->select count(*) from emp where count(*) >1 group by id;
 
Is this answer useful? Yes | No
December 27, 2006 12:05:46   #8  
hasanvtu Member Since: October 2006   Contribution: 11    

RE: How we can count duplicate entry in particular tab...
itS NOT WORKING AND HOW TO SELECT DUPLICATE RECORDS.
 
Is this answer useful? Yes | No
January 31, 2007 06:31:25   #9  
Deepak        

RE: How we can count duplicate entry in particular tab...
ySQL said: Documentation#1111 - Invalid use of group function
 
Is this answer useful? Yes | No
May 21, 2007 06:51:13   #10  
venkat        

RE: How we can count duplicate entry in particular tab...
Mysql supports count(*) and Count

Using Mysql count is retrieving the all not null record in the table
count(*) gives the all record including not null and null record in the table

 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape