My query currently is:
SELECT x, MAX(z) AS mz, y FROM my_table GROUP BY x
The columns x and mz are returned as expected, but the last column, y, does not match up with the other two. In other words, I want the "y" column to match the mz column just like the x column currently does. How do I pull that off?
UPDATE: Sorry, the question wasn't very clear. I want to perform the following query:
SELECT * FROM (SELECT x, MAX(z) AS mz FROM my_table GROUP BY x) a RIGHT JOIN (SELECT y, MAX(z) AS mz FROM my_table GROUP BY y) b ON a.mz = b.mz
without having to use 3 SELECT statements (Perhaps that's not a big deal, but it seems like an inefficient query to me. But I'm pretty new at sql queries, so I dunno.)
UPDATE #2: Lets say my table looks like this:
-------------------
| x | y | z |
-------------------
| 45 | h | 3 |
| 23 | c | 5 |
| 45 | e | 9 |
| 23 | b | 12 |
| 45 | x | 36 |
| 33 | s | 44 |
| 33 | p | 78 |
-------------------
I want to return the following:
-------------------
| x | y | z |
-------------------
| 23 | b | 12 |
| 45 | x | 36 |
| 33 | p | 78 |
-------------------