Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 08-13-2013, 01:49 AM
stephen001 stephen001 is offline
Contributing Member
 
Join Date: 04-25-13
Posts: 89
iTrader: 0 / 0%
how to get the duplicate records from mysql query

how to get the duplicate records from mysql query

I have empid and week field, I want to see is there any duplicate week entry for any employee
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 08-15-2013, 04:54 AM
megamoose's Avatar
megamoose megamoose is offline
v7n Mentor
 
Join Date: 06-04-06
Location: Guildford
Posts: 557
iTrader: 2 / 100%
You could start by doing a:
Code:
SELECT week, count(empid) FROM table_name GROUP BY count(empid) > 1
This will return only rows that are duplicated. From that you could potentially run another SQL script to delete them, or just do this manually.

Last edited by megamoose; 08-15-2013 at 04:55 AM. Reason: posted too soon
 
Reply With Quote
  #3  
Old 08-21-2013, 04:49 AM
stephen001 stephen001 is offline
Contributing Member
 
Join Date: 04-25-13
Posts: 89
iTrader: 0 / 0%
Quote:
Originally Posted by megamoose View Post
You could start by doing a:
Code:
SELECT week, count(empid) FROM table_name GROUP BY count(empid) > 1
This will return only rows that are duplicated. From that you could potentially run another SQL script to delete them, or just do this manually.
I am getting a error Invalid Use of Group function while running this query
 
Reply With Quote
  #4  
Old 08-21-2013, 02:29 PM
megamoose's Avatar
megamoose megamoose is offline
v7n Mentor
 
Join Date: 06-04-06
Location: Guildford
Posts: 557
iTrader: 2 / 100%
Sorry my mistake. You need to put a having in there:
Code:
SELECT week, count(empid) FROM table_name GROUP BY count(empid) HAVING count(empid) > 1
 
Reply With Quote
  #5  
Old 08-22-2013, 05:07 AM
stephen001 stephen001 is offline
Contributing Member
 
Join Date: 04-25-13
Posts: 89
iTrader: 0 / 0%
Quote:
Originally Posted by megamoose View Post
Sorry my mistake. You need to put a having in there:
Code:
SELECT week, count(empid) FROM table_name GROUP BY count(empid) HAVING count(empid) > 1
still same result Invalid Use of Group function
 
Reply With Quote
  #6  
Old 08-22-2013, 08:14 AM
Douglas's Avatar
Douglas Douglas is offline
Contributing Member
 
Join Date: 08-21-13
Location: Atlanta, GA
Posts: 61
iTrader: 0 / 0%
Shouldn't the GRUOP BY count(empid) be simply ORDER BY empid? The having line should stay.
 
Reply With Quote
  #7  
Old 08-23-2013, 11:09 AM
megamoose's Avatar
megamoose megamoose is offline
v7n Mentor
 
Join Date: 06-04-06
Location: Guildford
Posts: 557
iTrader: 2 / 100%
I think the GROUP BY should be Week:
Code:
SELECT week, count(empid) FROM table_name GROUP BY week HAVING count(empid) > 1
Sorry I should concentrate more, or make a sample table to try it on
 
Reply With Quote
  #8  
Old 08-27-2013, 05:25 AM
stephen001 stephen001 is offline
Contributing Member
 
Join Date: 04-25-13
Posts: 89
iTrader: 0 / 0%
can I use mysql_query function to get true or false if record exist ?

can we use
CODE: SELECT ALL
mysql_query
to validate whether any record with week = '2013-04-20' already exist or not ?

if not can anyone tell any validation function which returns true or false if we pass query to it

CODE: SELECT ALL
PHP Code:
$returnval mysql_query("select * from emp where week='2013-04-20') 

CODE: SELECT ALL
PHP Code:
if(! $returnval)
{
 echo 
"no record exist";

else
   echo 
"record exist"

Last edited by snakeair; 08-27-2013 at 06:27 AM.
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql / php search query robpicken Coding Forum 1 05-19-2013 01:52 PM
PHP/Mysql query problem!!! gdeliana Coding Forum 2 10-24-2012 10:58 AM
Mysql Help: Counting within query tashbaqa Coding Forum 4 04-06-2011 02:31 PM
Which one faster mysql query? smith Coding Forum 7 03-29-2007 04:41 AM
MYSQL Update Query Limit Coding Forum 1 12-26-2004 10:08 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 10:15 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC