Here is my situation: I have a table which duplicated values are valid (except by the ID field), and I’d like to retrieve only unique values.
For instance, if I have the registers:
+----+--------------+-------------+------+------+-------+-----+
| ID | SATELLITE_ID | ATT_TYPE_ID | TIME | ROLL | PITCH | YAW |
+----+--------------+-------------+------+------+-------+-----+
| 1 | 1 | 1 | 2012 | 1.0 | 2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+
| 2 | 1 | 1 | 2012 | 1.0 | 2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+
| 3 | 1 | 1 | 2011 | 1.0 | 2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+
I’d like to retrieve just 2 and 3 (ID 1 and 2 are “equal”, and 3 has different TIME).
Here it is the table structure
mysql> describe attitude;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| SATELLITE_ID | int(11) | NO | | NULL | |
| ATT_TYPE_ID | int(11) | NO | | NULL | |
| TIME | varchar(4) | NO | | NULL | |
| ROLL | double | NO | | NULL | |
| PITCH | double | NO | | NULL | |
| YAW | double | NO | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
Thx.
You can apply the
max()aggregate to theIDcolumn and thenGROUP BYthe rest:See SQL Fiddle with Demo
Result: