I have a table called x, the table has id column and repeat status column. The id can store same values even 6 of them while the repeat status increments each time an id is inserted 1,2…n. If a new different id is inserted the repeat status starts from 1 e.g
xid repeat_status
xx123 1
xx123 1
xx123 2
xx123 3
xx123 3
xxx45 1
xxx45 2
xxx45 2
How can I modify the query below to return something like this:
xid repeat_status
xx123 1
xx123 2
xx123 3
xxx45 1
xxx45 2
SELECT xid
,repeat_status
FROM x
GROUP BY repeat_status;
you can also try group by query like this
Post : What is difference between DISTINCT and GROUP BY?
A DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same across both query constructs.
but this is for sql server not have idea bout mysql