我有一个包含太多列和几百万行的表,我需要查询其中的差异。
在这些行上,希望只有一列不同,并且应该是自动递增 id 字段。
我需要做的是检查这些行是否实际上相同,以及是否有任何字段存在差异。
例如,如果“Name”列应该是“Peter、Paul 和 Mary”,“Order #”列应该是“132”,我需要找到这些值不存在的任何行是的,但我需要为表中的每一列找到它 AND 我实际上不知道正确的值是什么(这意味着我不能只创建一个“SELECT...WHERE Name=每列的“此”)。
那么如何找到不同的行呢? (使用直接 SQL,无需编程)
最佳答案
您认为这个答案是您正在寻找的并且会对您有帮助吗?这是 Link找到合适的sql查询。
Let's suppose you coded a email newsletter signup form, but you forgot to double check that the email address was not a duplicate, or already in the database. We can write a query to find all the emails in our table that are duplicates, or occurs in more than one row.
The following SQL query works great for finding duplicate values in a table.
SELECT email, COUNT(email) AS NumOccurrences FROM users GROUP BY email HAVING ( COUNT(email) > 1 )
By using group by and then having a count greater than one, we find rows with with duplicate email addresses using the above SQL. Blockquote
关于sql - 选择 SQL 中不同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1764663/