I have a table T
with columns x
,y
,a
,b
such that
SELECT x,y,a,b FROM T
ORDER BY x,y,a,b
gives me the following table
x | y | a | b
x1 | y1 | a1 | b1
x1 | y1 | a1 | b2
x1 | y1 | a2 | b1
x1 | y2 | a1 | b1
x1 | y2 | a1 | b2
x1 | y2 | a2 | b1
How would I get the first row of each x,y group? That is, how would I get the following table
x | y | a | b
x1 | y1 | a1 | b1
x1 | y2 | a1 | b1
Here is a second example: For a table T such that
x | y | a | b
x1 | y1 | a1 | b3
x1 | y1 | a1 | b4
x1 | y1 | a2 | b1
x1 | y1 | a2 | b2
x1 | y2 | a1 | b3
x1 | y2 | a1 | b4
x1 | y2 | a2 | b1
x1 | y2 | a2 | b2
I am expecting to get
x | y | a | b
x1 | y1 | a1 | b3
x1 | y2 | a1 | b3