How to ignore a query line in the database?

Asked

Viewed 56 times

-1

I am trying to develop a code to create dynamic tables with php and mysql, using an Asterisk database. My first difficulty is that the recording of calls are duplicated (or quadrupled), if the connection is internal. For example, if I use the command:

SELECT calldate, src, dst, duration, disposition
FROM cdr 
ORDER BY calldate DESC
LIMIT 8;

This result is obtained:

+---------------------+------+------+----------+-------------+
| calldate            | src  | dst  | duration | disposition |
+---------------------+------+------+----------+-------------+
| 2020-12-15 08:43:27 | 5003 | 5010 |      505 | ANSWERED    |
| 2020-12-15 08:42:32 | 5001 | 5006 |       34 | ANSWERED    |
| 2020-12-15 08:41:42 | 5001 | 5006 |       34 | ANSWERED    |
| 2020-12-15 08:39:15 | 5006 | 5010 |       34 | ANSWERED    |
| 2020-12-15 08:38:26 | 5006 | 5010 |       34 | ANSWERED    |
| 2020-12-15 08:36:30 | 5001 | 5008 |       36 | ANSWERED    |
| 2020-12-15 08:36:06 | 5004 | 5001 |        0 | BUSY        |
| 2020-12-15 08:35:46 | 5004 | 5001 |       20 | BUSY        |
+---------------------+------+------+----------+-------------+
8 rows in set (0.09 sec)

How can I get around that?

  • SELECT DISTINCT src, dst, ...

  • The table you posted in the question has no duplicate records. Duplicated would be if all the data of a record (line) were equal to those of another line. As the calldates are all different, there is no duplication of records.

2 answers

1

You can use the distinct to distinguish the results of select, but in this case I believe you want to distinguish only by the column "disposition", since it is the only duplicated/quadrupled in the example.

But I believe that the most correct would be for you to perform a treatment in your table to avoid duplicate records, which can be done with the Unic.

I hope I helped, if not, please supplement your question.

1

Try this:

SELECT max(calldate) calldateMax, src, dst, duration, disposition
FROM cdr 
group by src, dst, duration, disposition
ORDER BY calldateMax DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.