Question
SQL find dupicate select statment
Questoin on syntax.
This works and does a join to pull all the records:
"SELECT a.*,b.* FROM dataBase.members AS a LEFT OUTER JOIN
dataBase.group_name AS b ON a.user_newsletter = b.group_id
ORDER BY user_joind_date DESC"
No I need to check for duplicate IP addresses and pair them together with the newest date first. So for example if we find say 100 records that have duplicates it would pair the duplicates togeter. And start with the newest date first even if the second or third and so on duplicates have older dates.
Like this:
Record: 85 IP:200.118.166.193 Date: 5/9/2007
Record: 65 IP:200.118.166.193 Date: 2/9/2007
Record: 35 IP:200.118.166.193 Date: 1/10/2007
Record: 84 IP:72.92.3.62 Date: 5/8/2007
Record: 85 IP:72.92.3.62 Date: 5/7/2007
And I know the following is not correct.
Any one the correct way to write what I am trying do?
"SELECT a.*,b.*
count(a.user_IP) AS NumOccourrences
FROM dataBase.members AS a LEFT OUTER JOIN
dataBase.group_name AS b ON a.user_newsletter = b.group_id
Group by a.user_IP Having ( COUNT(a.user_IP) > 1 )
ORDER BY user_joind_date DESC"
This works and does a join to pull all the records:
"SELECT a.*,b.* FROM dataBase.members AS a LEFT OUTER JOIN
dataBase.group_name AS b ON a.user_newsletter = b.group_id
ORDER BY user_joind_date DESC"
No I need to check for duplicate IP addresses and pair them together with the newest date first. So for example if we find say 100 records that have duplicates it would pair the duplicates togeter. And start with the newest date first even if the second or third and so on duplicates have older dates.
Like this:
Record: 85 IP:200.118.166.193 Date: 5/9/2007
Record: 65 IP:200.118.166.193 Date: 2/9/2007
Record: 35 IP:200.118.166.193 Date: 1/10/2007
Record: 84 IP:72.92.3.62 Date: 5/8/2007
Record: 85 IP:72.92.3.62 Date: 5/7/2007
And I know the following is not correct.
Any one the correct way to write what I am trying do?
"SELECT a.*,b.*
count(a.user_IP) AS NumOccourrences
FROM dataBase.members AS a LEFT OUTER JOIN
dataBase.group_name AS b ON a.user_newsletter = b.group_id
Group by a.user_IP Having ( COUNT(a.user_IP) > 1 )
ORDER BY user_joind_date DESC"
