0
SQL find dupicate select statment

/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/td-p/526997
May 09, 2007
May 09, 2007
Copy link to clipboard
Copied
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"
TOPICS
Server side applications
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/526998#M170389
May 09, 2007
May 09, 2007
Copy link to clipboard
Copied
Just use ORDER BY user_IP DESC, user_joind_date DESC. This
will first order everything by the IP, then is will order it by the
date.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/526999#M170390
May 09, 2007
May 09, 2007
Copy link to clipboard
Copied
Well I have thousands of records. Just want to pair up and
view the dupicate IPs not all the records.
But thanks that helps a little
But thanks that helps a little
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/527000#M170391
May 09, 2007
May 09, 2007
Copy link to clipboard
Copied
Then use a WHERE statement to narrow your results.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/527001#M170392
May 10, 2007
May 10, 2007
Copy link to clipboard
Copied
Why are you using SELECT *?
If you want to see the entire record from all records with duplicate IPs,
you'll need a subquery.
It will look something like this:
SELECT A.Record, A.User_IP, A.User_Join_Date, [anything else you want to see
for this task]
FROM database.members A
INNER JOIN (SELECT User_IP FROM database.members GROUP BY UserIP HAVING
COUNT(*) > 1) AS A_Dups ON A.User_IP = A_Dups.User_IP
ORDER BY A.User_IP, A.User_Join_Date
I didn't see anything from your groups table in the results you wanted, so I
left it out.
Above, you're joining your members to a derived table that contains a list
of all IPs that are duplicated. That means the resulting join gives you all
records that have an IP duplicated in some other record. The ORDER BY then
puts them in the order you wanted - all the IPs together with the oldest
record first.
Hope that helps.
If you want to see the entire record from all records with duplicate IPs,
you'll need a subquery.
It will look something like this:
SELECT A.Record, A.User_IP, A.User_Join_Date, [anything else you want to see
for this task]
FROM database.members A
INNER JOIN (SELECT User_IP FROM database.members GROUP BY UserIP HAVING
COUNT(*) > 1) AS A_Dups ON A.User_IP = A_Dups.User_IP
ORDER BY A.User_IP, A.User_Join_Date
I didn't see anything from your groups table in the results you wanted, so I
left it out.
Above, you're joining your members to a derived table that contains a list
of all IPs that are duplicated. That means the resulting join gives you all
records that have an IP duplicated in some other record. The ORDER BY then
puts them in the order you wanted - all the IPs together with the oldest
record first.
Hope that helps.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/527002#M170393
May 10, 2007
May 10, 2007
Copy link to clipboard
Copied
I would do it something like
select id, count(fld) cnt into #temp
Select s.flds
where temp.id = s.id and temp.cnt > 1
--
select id, count(fld) cnt into #temp
Select s.flds
where temp.id = s.id and temp.cnt > 1
--
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/527003#M170394
May 10, 2007
May 10, 2007
Copy link to clipboard
Copied
Which from what I can see would produce an error!
Anyway, why use a temp table when you do not need to? That is an enormous
waste of resources which is simply not needed.
"Philo" <meansyou@nospam.net> wrote in message
news:f1v6bd$8i3$1@forums.macromedia.com...
>I would do it something like
>
> select id, count(fld) cnt into #temp
>
> Select s.flds
> where temp.id = s.id and temp.cnt > 1
>
>
>
> --
>
Anyway, why use a temp table when you do not need to? That is an enormous
waste of resources which is simply not needed.
"Philo" <meansyou@nospam.net> wrote in message
news:f1v6bd$8i3$1@forums.macromedia.com...
>I would do it something like
>
> select id, count(fld) cnt into #temp
>
> Select s.flds
> where temp.id = s.id and temp.cnt > 1
>
>
>
> --
>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/dreamweaver-discussions/sql-find-dupicate-select-statment/m-p/527004#M170395
May 11, 2007
May 11, 2007
Copy link to clipboard
Copied
JimBo wrote:
> Which from what I can see would produce an error!
>
> Anyway, why use a temp table when you do not need to? That is an
> enormous waste of resources which is simply not needed.
>
I got the idea this was a one time thing, not recurring. In my
reasoning a temp table would consume less time start to finish.
> Which from what I can see would produce an error!
>
> Anyway, why use a temp table when you do not need to? That is an
> enormous waste of resources which is simply not needed.
>
I got the idea this was a one time thing, not recurring. In my
reasoning a temp table would consume less time start to finish.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

