

Sql Query to find duplicates in 2 columns where the values in the first column...
source link: https://www.codesd.com/item/sql-query-to-find-duplicates-in-2-columns-where-the-values-in-the-first-column-are-the-same.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Sql Query to find duplicates in 2 columns where the values in the first column are the same
I have a table where the first column contains States and second column contains Zip Code. I want to find duplicate Zip Codes in the same State. So, the first column can have same values but i need to find the duplicates in the second column that have the same values in the first column.
Table :
+---+----+------+
| Z | A | B |
+---+----+------+
| 1 | GA | 1234 |
| 2 | GA | 321 |
| 3 | GA | 234 |
| 4 | GA | 9890 |
| 5 | GA | 1234 |
+---+----+------+
The query should return the value of the zip code that has a duplicate i.e 1234. I have around 10000+ records.
Thank You.
Try using a GROUP BY
query and retain zip codes appearing in duplicate.
SELECT A, B
FROM yourTable
GROUP BY A, B
HAVING COUNT(*) > 1
Note that we can group by state and zip code assuming that a given zip code only appears once, for a given state.
Recommend
-
59
In this article we will discuss how to sort rows in ascending and descending order based on values in a single or multiple columns . Also, how to sort columns based on values in rows using DataFrame.sort_values()
-
8
drop columns that take fewer n values? advertisements Suppose i have a data frame like the following: df <- data.frame(v1 =...
-
4
Count Unique Values in all Columns of Pandas Dataframe – thisPointer.comSkip to content This article will discuss different ways to...
-
13
Join 2 primary key columns to 1 foreign key column in the same table advertisements I have a jobs...
-
3
Isaac DH 16 hours ago Removing Duplicates from several columns in Crystal Reports 32 Views
-
13
What length of hash byte column that can all...
-
10
Search Questions and Answers
-
3
In this article, we will discuss different ways to select all columns of a Pandas dataFrame except one specified column. Table Of Contents what do you mean by DataFrame...
-
11
In this article, we will discuss how to split a DataFrame column into two columns in Python. Table Of Contents Overview Pandas DataFrame In Pandas, the DataFrame contains thre...
-
5
February 23, 2023 /
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK