Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Dealing with duplicate values in mysql rows
Old 11-25-2008, 09:36 AM Dealing with duplicate values in mysql rows
downliner's Avatar
Extreme Talker

Posts: 209
Location: Orkney
Trades: 1
One of my mysql tables has duplicate rows and I'm cautious about just deleting them due to their auto increment ID's. I'm needing a fix for the below SQL query so that search result repetitions are limited to only being shown once ~ four hours of Googling and I still can't fathom what to do .

PHP Code:
$productQuery="SELECT C.*,I.* FROM `colour` AS `C` Left Join `product_inventory` AS `I` ON `C`.`productId` = `I`.`productId` where C.Colour_Id=".$_GET['colour'].$whrStr.$orderSort
Thats not the whole query, just the relevant part.

To find the duplicates I used:

PHP Code:
SELECT productIdColour_IdCOUNT(*) FROM colour
GROUP BY productId
Colour_Id HAVING COUNT(*) > 
From what I've read I need to use SELECT DISTINCT though I can't work out how it applies to my query.

Anyone?
__________________

Please login or register to view this content. Registration is FREE
downliner is offline
Reply With Quote
View Public Profile Visit downliner's homepage!
 
 
Register now for full access!
Old 11-25-2008, 09:53 AM Re: Dealing with duplicate values in mysql rows
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
don't worry about auto increment id numbers, the database holds the last ID used separately to the data. So even deleting the last record added won't cause a problem.

If you don't need them, delete them.

SELECT DISTINCT fieldlist works across ALL the fields, so every column in the row will have to be identical for the record to be excluded.

Use the GROUP BY query to compress the duplicate records
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Dealing with duplicate values in mysql rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21631 seconds with 12 queries