Mysql - Select only rows where column has unique value

10,764

Solution 1

SELECT 
    ID, 
    SATTELLITE_ID, 
    ATT_TYPE_ID, 
    TIME, 
    ROLL, 
    PITCH, 
    YAW 
FROM Table 
GROUP BY 
    SATTELLITE_ID, 
    ATT_TYPE_ID, 
    TIME, 
    ROLL, 
    PITCH, 
    YAW 
HAVING COUNT(*) = 1

Solution 2

Try this:

SELECT * FROM temptbl 
GROUP BY satellite_id, att_type_id, time, roll, pitch, yaw 
HAVING COUNT(*) = 1;

Solution 3

use group by with having count(*) = 1

Share:
10,764
Jeffrey L. Roberts
Author by

Jeffrey L. Roberts

Updated on June 13, 2022

Comments

  • Jeffrey L. Roberts
    Jeffrey L. Roberts almost 2 years

    The closest thing I found to what I am looking for is, so I will use it as an example

    MySQL: Select rows that have only unique values except for a column

    Given this dataset

    +----+--------------+-------------+------+------+-------+-----+
    | 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 would like to return only

    +----+--------------+-------------+------+------+-------+-----+
    | ID | SATELLITE_ID | ATT_TYPE_ID | TIME | ROLL | PITCH | YAW |
    +----+--------------+-------------+------+------+-------+-----+
    |  3 |            1 |           1 | 2011 |  1.0 |   2.0 | 1.3 |
    +----+--------------+-------------+------+------+-------+-----+
    

    because it is the only unique row

    Is this possible with mysql?