Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

SQL script

Hi. Have a table that contains account information such as name, address, email, telephone number, etc.

Need syntax to return any persons name that have the same telephone number listed more than x times. So, when the query is executed, it will only look for telephone numbers that have been listed more than x times and will return the persons name and address.

Thanks in advance.
1 Solution
Raja Jegan RSQL Server DBA & ArchitectCommented:
Here you go:

select name, address
FROM ur_table
WHERE phone_no in (
Select telephone_no
FROM ur_table
Group by telephone_no
having COUNT(*) > 1)
Alpesh PatelAssistant ConsultantCommented:
select name, phone_no, Count(phone_no) FROM table
Group by name
having COUNT(phone_no) > 1)
Bhavesh ShahLead AnalysistCommented:

Rajan Sir already gave you answer, but just for your knowledge

SELECT  name, address, email, phone_no
FROM table1 A,(Select name from table1 group by name having count(phone_no)>1) B
WHERE A.name = B.name

- Bhavesh
Try this

I go with PatelAlpesh's comment, but insert x in place of 1, from a form field. This allows for different x values.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now