Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 265 characters in body; edited title
Source Link
marc_s
  • 760k
  • 186
  • 1.4k
  • 1.5k

MS SQL Server query for finding duplicate rows from identical tables

I have a question about finding identical rows from one table to another. I have a table for users to ask for information. So with that the query will be ran against another table. Both tables are identical except for the ID columns. 

The ID columns are not involved in the query except for the SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC 

part.

My query looks like this

SELECT TOP 1 *   FROM searchTable   ORDER BY searchid DESC(SELECT A.column1, A.column2,..............  FROM dbo.searchTable A    WHERE EXISTS (SELECT * FROM realTable B  WHERE A.Column1=BColumn1 = B.Column1  AND A.Column2=BColumn2 = B.Column2, ....... AND A.lastColumn=BlastColumn = B.lastColumn)) 

What I get when running the query is the last inputtedentered query from the query table, which is correct, but I get all the rows listed from the realTable as if everything after WHERE EXISTSWHERE EXISTS is pointless. What I need is the single row query from the queryTable to list all the rows that are identical to it from the realTable. Not all the rows the realTable has.

MS SQL query for finding duplicate rows from identical tables

I have a question about finding identical rows from one table to another. I have a table for users to ask for information. So with that the query will be ran against another table. Both tables are identical except for the ID columns. The ID columns are not involved in the query except for the SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC part

My query looks like this

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC(SELECT A.column1, A.column2,.............. FROM dbo.searchTable A   WHERE EXISTS(SELECT * FROM realTable B WHERE A.Column1=B.Column1 AND A.Column2=B.Column2,.......AND A.lastColumn=B.lastColumn)) 

What I get when running the query is the last inputted query from the query table, which is correct, but I get all the rows listed from the realTable as if everything after WHERE EXISTS is pointless. What I need is the single row query from the queryTable to list all the rows that are identical to it from the realTable. Not all the rows the realTable has.

SQL Server query for finding duplicate rows from identical tables

I have a question about finding identical rows from one table to another. I have a table for users to ask for information. So with that the query will be ran against another table. Both tables are identical except for the ID columns. 

The ID columns are not involved in the query except for the

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC 

part.

My query looks like this

SELECT TOP 1 *   FROM searchTable   ORDER BY searchid DESC(SELECT A.column1, A.column2,..............  FROM dbo.searchTable A  WHERE EXISTS (SELECT * FROM realTable B  WHERE A.Column1 = B.Column1  AND A.Column2 = B.Column2, ....... AND A.lastColumn = B.lastColumn)) 

What I get when running the query is the last entered query from the query table, which is correct, but I get all the rows listed from the realTable as if everything after WHERE EXISTS is pointless. What I need is the single row query from the queryTable to list all the rows that are identical to it from the realTable. Not all the rows the realTable has.

format code
Source Link
Alex Kudryashev
  • 9.5k
  • 3
  • 31
  • 39

I have a question about finding identical rows from one table to another. I have a table for users to ask for information. So with that the query will be ran against another table. Both tables are identical except for the ID columns. The ID columns are not involved in the query except for the SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC part

My query looks like this

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC(SELECT A.column1, A.column2,.............. FROM dbo.searchTable A

WHERE EXISTS(SELECT * FROM realTable B WHERE A.Column1=B.Column1 AND A.Column2=B.Column2,.......AND A.lastColumn=B.lastColumn))

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC(SELECT A.column1, A.column2,.............. FROM dbo.searchTable A WHERE EXISTS(SELECT * FROM realTable B WHERE A.Column1=B.Column1 AND A.Column2=B.Column2,.......AND A.lastColumn=B.lastColumn)) 

What I get when running the query is the last inputted query from the query table, which is correct, but I get all the rows listed from the realTablerealTable as if everything after WHERE EXISTS is pointless. What I need is the single row query from the queryTablequeryTable to list all the rows that are identical to it from the realTablerealTable. Not all the rows the realTablerealTable has.

I have a question about finding identical rows from one table to another. I have a table for users to ask for information. So with that the query will be ran against another table. Both tables are identical except for the ID columns. The ID columns are not involved in the query except for the SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC part

My query looks like this

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC(SELECT A.column1, A.column2,.............. FROM dbo.searchTable A

WHERE EXISTS(SELECT * FROM realTable B WHERE A.Column1=B.Column1 AND A.Column2=B.Column2,.......AND A.lastColumn=B.lastColumn))

What I get when running the query is the last inputted query from the query table, which is correct, but I get all the rows listed from the realTable as if everything after WHERE EXISTS is pointless. What I need is the single row query from the queryTable to list all the rows that are identical to it from the realTable. Not all the rows the realTable has.

I have a question about finding identical rows from one table to another. I have a table for users to ask for information. So with that the query will be ran against another table. Both tables are identical except for the ID columns. The ID columns are not involved in the query except for the SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC part

My query looks like this

SELECT TOP 1 * FROM searchTable ORDER BY searchid DESC(SELECT A.column1, A.column2,.............. FROM dbo.searchTable A WHERE EXISTS(SELECT * FROM realTable B WHERE A.Column1=B.Column1 AND A.Column2=B.Column2,.......AND A.lastColumn=B.lastColumn)) 

What I get when running the query is the last inputted query from the query table, which is correct, but I get all the rows listed from the realTable as if everything after WHERE EXISTS is pointless. What I need is the single row query from the queryTable to list all the rows that are identical to it from the realTable. Not all the rows the realTable has.

Source Link
Loading