Find similar records in the same table

Find similar records in the same table

sql select duplicate rows based on one column
sql query to find duplicate rows in a table
how to find duplicate records in sql with condition
how to find count of duplicate rows
sql query to find duplicate records in a column
mysql select duplicate records only
get count of duplicate rows in mysql
mysql find duplicate values multiple columns

I am looking for similar records in the same table. I tried IN clause (below query) but it is not working as per the expectation. Select * from tblBlogCategory Where CategoryID IN (Select CategoryID from tblBlogCategory Where BlogID=1) i.e. I have BlogID=1. I want those records in the table whose CategoryID is 1 and 2 both. It is also fine if any new CategoryID 3 is there. So, for the below table, It should return BlogID 3. How do I achieve this?

Expected Output:


Try this:

Table Schema:

CREATE TABLE YourTable(BlogId INT, CategoryId INT)

INSERT INTO YourTable VALUES(1,1)
INSERT INTO YourTable VALUES(1,2)
INSERT INTO YourTable VALUES(2,1)
INSERT INTO YourTable VALUES(3,1)
INSERT INTO YourTable VALUES(3,2)
INSERT INTO YourTable VALUES(3,3)

Query:

DECLARE @BlogID INT = 1

SELECT * 
FROM YourTable  
WHERE BlogID IN(
    SELECT A.BlogID 
    FROM YourTable A
    JOIN (
        SELECT CategoryId
        FROM YourTable
        WHERE BlogID = @BlogID
    )B ON A.CategoryId = B.CategoryId
    GROUP BY A.BlogID
    HAVING COUNT(DISTINCT A.CategoryId)>=(SELECT COUNT(DISTINCT CategoryId) FROM YourTable WHERE BlogID = @BlogID)
  )
AND BlogID != @BlogID

Output:

| BlogId | CategoryId |
|--------|------------|
|      3 |          1 |
|      3 |          2 |
|      3 |          3 |

SQL Fiddle Link

Find duplicates in the same table in MySQL, What query can I run to show duplicate records? e.g. my table is ArtistX : 45677 ArtistY : 378798� I have a Microsoft SQL Server 2012 database table with around 7 million crowd-sourced records, primarily containing a string name value with some related details. For nearly every record it seems t


If I got you correctly, You could use

select * from tblBlogCategory where BlogID=1

you should get all CategoryID where BlogID=1 which you may also further filter

 select * from tblBlogCategory where BlogID=1 and CategoryID in (1,2)

How To Find Duplicate Values in MySQL, The find duplicate values in on one column of a table, you use follow these steps: First, use the GROUP BY clause to group all rows by the target column, which is the column that you want to check duplicate. Then, use the COUNT() function in the HAVING clause to check if any group have more than 1 element. I have been looking but I cant find a way to do quite what I want. For example if I have the following rows I would like to be able to select those with the same language, a time within 15 minutes of each other, and with names that share > 70% of the same characters.


If you just want to return blog ids that have matches, then this should be sufficient:

select bc.blogid
from tblBlogCategory bc join
     tblBlogCategory bc1
     on bc1.categoryid = bc.categoryid and
        bc1.blogid = 1 and
        bc1.blogid <> bc.blogid
group by bc.blogid
having count(*) = (select count(*) from tblBlogCategory bc where bc.blogid = 1);

How to Find Duplicate Values in a SQL Table, However, you may find yourself working with a database where duplicate rows have been created through� similar articles. Grant table-level permissions in SQL Server. After launching and connecting to SQL Server Management Studio, create a new login and select the database that is connected to Chartio. Grant MySQL table and column permissions. You can grant a user table and column permissions in MySQL with GRANT statements. How to Select the


Find duplicate data in MySQL, when you need to find duplicate values available in a column of a MySql table. As the same quantity value exists in more than two records,� Reports any records in a feature class or table that have identical values in a list of fields, and generates a table listing these identical records. If the field Shape is selected, feature geometries are compared. The Delete Identical tool can be used to find and delete identical records.


Finding Duplicate Rows in SQL Server, Technically, you use the UNIQUE constraints to enforce the uniqueness of rows in one or more columns of a table. However, sometimes you may find duplicate� Compare Two Tables using UNION ALL UNION allows you to compare data from two similar tables or data sets. It also handles the NULL values to other NULL values which JOIN or WHERE clause doesn’t handle. It allows quickly checking what are the data missing or changed in either table.


Finding Duplicates with SQL, i want to get all the duplicate records in the table but i dont wont the original data . for eg, murali is a table name which has many names as one of its field ,in that� In the Show Table dialog box, double-click the table that contains the records that you want to display — in this example, the Class Enrollments table, and then double-click the table to which you are comparing it — in this example, the Student Majors table. Close the Show Table dialog box.