MySQL Forums
Forum List  »  General

Help with a SQL statement
Posted by: asakhi h
Date: February 23, 2017 07:15PM

Hello everyone,

I have in a table the following data. As you can see I have repeating SERIAL number, but with different UNIT number. I would like to list only one SERIAL number with the LOWEST UNIT number. i.e. the result of my query should be as follow:


EQUIPMENT
+-----------+------------------+-----------------------+------------+
|  ID       |  SERIAL          |  TAG                  | UNIT       |
+-----------+------------------+-----------------------+------------+
| 0001      |  AAAABBBB001     |  ABCDEFGH-0001        | 100        |
+-----------+------------------+-----------------------+------------+
| 0001      |  AAAABBBB001     |  ABCDEFGH-0001        | 110        |
+-----------+------------------+-----------------------+------------+
| 0001      |  CCCCBBBB002     |  ABCDEFGH-0001        | 500        |
+-----------+------------------+-----------------------+------------+
| 0001      |  CCCCBBBB002     |  ABCDEFGH-0001        | 550        |
+-----------+------------------+-----------------------+------------+
| 0001      |  CCCCBBBB002     |  ABCDEFGH-0001        | 600        |
+-----------+------------------+-----------------------+------------+
| 0001      |  EEEEBBBB001     |  ABCDEFGH-0001        | 200        |
+-----------+------------------+-----------------------+------------+
| 0001      |  EEEEBBBB001     |  ABCDEFGH-0001        | 201        |
+-----------+------------------+-----------------------+------------+
| 0001      |  FFFFBBBB001     |  ABCDEFGH-0001        | 999        |
+-----------+------------------+-----------------------+------------+
| 0001      |  FFFFBBBB001     |  ABCDEFGH-0001        | 800        |
+-----------+------------------+-----------------------+------------+


Result:
+-----------+------------------+-----------------------+------------+
|  ID       |  SERIAL          |  TAG                  | UNIT       |
+-----------+------------------+-----------------------+------------+
| 0001      |  AAAABBBB001     |  ABCDEFGH-0001        | 100        |
+-----------+------------------+-----------------------+------------+
| 0001      |  CCCCBBBB002     |  ABCDEFGH-0001        | 500        |
+-----------+------------------+-----------------------+------------+
| 0001      |  EEEEBBBB001     |  ABCDEFGH-0001        | 200        |
+-----------+------------------+-----------------------+------------+
| 0001      |  FFFFBBBB001     |  ABCDEFGH-0001        | 800        |
+-----------+------------------+-----------------------+------------+

Is it possible to achieve that?

Options: ReplyQuote


Subject
Written By
Posted
Help with a SQL statement
February 23, 2017 07:15PM
February 23, 2017 07:23PM
February 23, 2017 09:42PM
February 23, 2017 09:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.