I have the following query that I do in SQL server
select celular, razon_social FROM clientes where
celular <> '' AND LEN(celular) = '10'
AND ind_estado = '1' AND ISNUMERIC(celular) > 0
ORDER BY celular
it brings me records normally, what happens is that there are some records that are repeated in the field celular
but not in the field razon_social
for example these records
As you can see in the image there are 5 records: the record 13
and 14
have the same number celular
but different razon_social
, the records 15
, 16
and 17
have the same number celular
but different razon_social
.
What do I want?
that instead of bringing me those 5 records, bring me 2, I mean that of the repeated ones, it only brings 1 no matter which of the repeated ones I take, what interests me is that it brings me all records except if it is repeated on the cell phone, if it is repeated on the cell phone, it only brings me 1 of the repeated ones, but I do not want it to be excluded.
try modifying the query like this
select celular, razon_social FROM clientes where
celular <> '' AND LEN(celular) = '10'
AND ind_estado = '1' AND ISNUMERIC(celular) > 0
AND celular in (SELECT celular from clientes GROUP
BY celular HAVING count(*)=1)
ORDER BY celular
but I exclude the repeated ones
It should be said that there are many other records that are repeated 2, 3 or even more times in the cell, which I put are just some examples.