I have a my SQL results similar to below. I have been using rails and would like to have solution either in SQL
or Rails
id | name | addr | add_id
-------------------------
1 | m | Q | 15
2 | n | Q | 3
3 | o | Q | 37
4 | f | R | 8
5 | c | A | 1
6 | r | M | 6
7 | v | W | 20
8 | z | T | 4
What I was trying is to get only one row if there are multiple rows having common data in one of the column. For example, in the above results, I have Id 1, 2 and 3
having common addr
as Q
. However, I would like to eliminate this behavior and want my results as below only taking one of the row's if there is repetition on one column. Anticipated results.
id | name | addr | add_id
-------------------------
1 | m | Q | 15
4 | f | R | 8
5 | c | A | 1
6 | r | M | 6
7 | v | W | 20
8 | z | T | 4