Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select Only Multiple Rows

I have a table that contains the same values ​​in all its columns.

NAME NUMBER
HASAN 34ASF45
HASAN 28KH852
HASAN 34ASF45
ALİ 21ASD05
MEHMET 45TR563
MEHMET 45TR563
YUSUF 85LK523

What I want to do in this SQL table is to select rows containing the same values ​​in columns A and B during selection.

I want a query that will output the following

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

NAME NUMBER COUNT
HASAN 34ASF45 2
MEHMET 45TR563 2

>Solution :

You need GROUP BY and HAVING:

SELECT t.Name, t.Number, COUNT(*) AS Count
FROM dbo.YourTable AS t
GROUP BY t.Name, t.Number
HAVING COUNT(*) > 1;

Example on db<>fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading