ReeceSayer Posted November 2, 2012 Share Posted November 2, 2012 Hi, I'm trying to remove duplicates from my database table (vacancy). Currently using the following SQL statement: SELECT title, jobref, location, description, salary, apply FROM vacancy WHERE jobref IN (SELECT DISTINCT jobref FROM vacancy) However, this still brings back the duplicates, each statement works on its own (I.e. DISTINCT brings back unique values for that column, and SELECT * brings back all rows & Columns) so i'm not entirely sure why it's not working. If there's a simpler way of doing this i'm open to trying it out. Cheers Link to comment https://forums.phpfreaks.com/topic/270202-select-distinct-duplication/ Share on other sites More sharing options...
Barand Posted November 2, 2012 Share Posted November 2, 2012 This will get the details of those records with duplicated jobrefs (if that is what you are after) SELECT title, jobref, location, description, salary, apply FROM vacancy INNER JOIN ( SELECT jobref, COUNT(*) as tot FROM vacancy GROUP BY jobref HAVING tot > 1 ) as x USING (jobref) ORDER BY jobref Link to comment https://forums.phpfreaks.com/topic/270202-select-distinct-duplication/#findComment-1389656 Share on other sites More sharing options...
ReeceSayer Posted November 2, 2012 Author Share Posted November 2, 2012 This will get the details of those records with duplicated jobrefs (if that is what you are after) SELECT title, jobref, location, description, salary, apply FROM vacancy INNER JOIN ( SELECT jobref, COUNT(*) as tot FROM vacancy GROUP BY jobref HAVING tot > 1 ) as x USING (jobref) ORDER BY jobref Thanks works brilliantly, I've just used IGNORE when importing the data and set the jobrefs column to unique which also seems to do the job (i'm importing a different data-set every day and didn't want duplicates). Thanks again Link to comment https://forums.phpfreaks.com/topic/270202-select-distinct-duplication/#findComment-1389677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.