Jeremy Fisher - 7 months ago 36

MySQL Question

Here is a simplified version of my table:

It contains the columns

`employee_id column2 column3 x y`

and they are all

`NUMERIC`

I am having trouble writing a complicated MySQL query. I want to get all the

`employeeid`

`column3`

`column2`

`x`

`y`

`2 100 123.456 5 7`

1 234 123.456 5 7

3 100 456.789 5 10

4 100 123.456 5 7

The rows

`2 100 123.456 5 7`

`3 100 456.789 5 10`

`2`

`3`

`column2`

`100`

`100`

`x`

`y`

`x`

`y`

`x`

`y`

How can I compare the documents of table with other documents within itself?

Answer

```
SELECT e1.*
FROM employee e1
JOIN employee e2
ON e1.employee_id <> e2.employee_id
AND e1.column2 = e2.column2
AND e1.X <> e2.X
AND e1.Y <> e2.Y
```

But I guess your last condition should be

```
AND (e1.X <> e2.X OR e1.Y <> e2.Y)
```