D
D
Denis Nicholas2015-10-08 22:26:21
SQL
Denis Nicholas, 2015-10-08 22:26:21

How to exclude duplicates from two columns (SQL)?

There is a table (mails):
| id | to | from | ... |
You need to select from mail only those where the values ​​of both to and from are not repeated, i.e. for table
| id | to | from |
| 1 | 1 | 2 |
| 2 | 2 | 1 |
| 3 | 1 | 3 |
| 4 | 3 | 1 |
| 5 | 1 | 3 |
result
| id | user1 | user2 |
| 1 | 1 | 2 |
| 3 | 1 | 3 |

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-10-08
@dennikolas

SELECT DISTINCT `to ` , `from ` FROM mails;
Then change it for yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question