Forum Moderators: coopster

Message Too Old, No Replies

Count identical rows with value from two or more columns

         

rrreee2

2:01 pm on May 15, 2009 (gmt 0)

10+ Year Member



I need a query to count identical rows with value from 2 columns .ie

ID C2 C3
1 133 bajs
2 133 kiss
3 133 slida
4 133 bajs
5 133 kuk
6 134 bajs
7 134 kiss
8 134 slida
9 134 bajs

This would display four results, id 1 and 4 are the same, id 6 and 9 are the same. Can you help me with this query?

kaidok

8:56 pm on May 15, 2009 (gmt 0)

10+ Year Member



I would go getting the content of every row, controlling rows that have already been checked to be repeated. ( I think this can be done via mysql_data_seek and mysql_fetch_row, if not you can always use a SELECT ID,C2,C3 FROM Table Where id=num, incrementing num).

Once you get the row info, I'd make a query asking for the rows who have that C2 and C3) I would put the rows into an array that controls that are repeated and when checking the following row, this row would be jumped if it has already been registered.

The process would be the following...

Getting info of 1 1 133 bajs
Query for it giving 1 and 4, adding for to arrays that checks they are repeated.

Info for 2... Query for 2... Nothing
Info for 3... Query for 3... Nothing
4...The row has been processing jumping to 5.

Hope this helps, it's not what you were asking for but I think this cannot be done in a single query.

idfer

5:37 am on May 16, 2009 (gmt 0)

10+ Year Member



select c2, c3, count(*) n from yourtable group by c2, c3 order by n

Skip over the rows where n = 1. Hope this helps.