Domanda

I have the following table and want to group by

[name]             [phone]
doniking           081222222222
doni               081222222222
Bambang Gentholet  081111111111
Bambang            081111111111

I want to get this result:

[name]             [phone]
doniking           081222222222
Bambang Gentholet  081111111111
È stato utile?

Soluzione 2

Try this

SELECT [name],[phone] 
FROM (
      SELECT *,Row_Number() Over (Partition By phone Order By (Select Null)) AS RN
      FROM Table1
      ) AS T
Where RN = 1
OFFSET n ROWS

You can replace n with your custom values...

Row_Number

Altri suggerimenti

Try this

SELECT MAX(name), phone  FROM <TableName> group by phone

EDIT: for offset

SELECT MAX(name), phone  FROM <TableName> group by phone
order by phone offset 10 rows 
FETCH NEXT 5 ROWS ONLY;

Check this for further details.

Try this

SELECT name, 
   phone 
FROM  (SELECT *, 
          Row_number() 
            OVER( 
              partition BY phone 
              ORDER BY name) row_num -- or you can have order by (select null)
   FROM   table1) t 
WHERE  row_num = 1 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top