MySQL Forums
Forum List  »  Newbie

Re: Select unique data
Posted by: Phillip Ward
Date: February 06, 2023 08:56AM

If you only want those four values ("from the third column") then what values from the other columns do you want to come with them (if any)?

The simplest solution is:

 
select distinct src
from cdr ; 

+--------------+
| src          |
+--------------+
| +48601513000 |
| +48609945000 |
| 500478000    |
| 609945000    |
+--------------+

But that's all you get.
If that's all you need, then that's great. Job Done.

If not, then you need to work out which of the other values to return.
For example, given these three records for a given src value:

select * from cdr 
where ... 

+---------------------+--------------+----------+
| calldate            | src          | duration |
+---------------------+--------------+----------+
| 2023-02-02 13:53:23 | +48601513000 |        4 |
| 2023-02-02 13:54:14 | +48601513000 |        7 |
| 2023-02-02 13:54:15 | +48601513000 |        6 |
+---------------------+--------------+----------+

As well as the src value, do you want:
- the first date,
- the last date,
- the shortest call duration,
- the longest call duration,
- the total call time,
- the average call time,
- something else entirely?

There are SQL aggregate functions that will cater to most, if not all, of your needs.

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
February 06, 2023 02:21AM
Re: Select unique data
February 06, 2023 08:56AM
February 07, 2023 04:26AM
February 07, 2023 08:12AM


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.