Home > Back-end >  Checking whether two tables have the same number of rows never finishes. What's wrong with this
Checking whether two tables have the same number of rows never finishes. What's wrong with this

Time:09-10

I'm using SQLite 3.39.3.

I came up with this query to check whether two tables have the same number of rows:

SELECT COUNT(a.auth_id)=COUNT(b.auth_scopus_id) FROM auth_subject_areas_mapping AS a, auth_subject_areas_mapping_old AS b; 

But the query never finishes. EXPLAIN QUERY PLAN gives me:

enter image description here

Questions:

  1. What's wrong with my query?
  2. What is the correct way in SQLite to check whether two tables have the same number of rows?

CodePudding user response:

WITH
    acount AS (SELECT count(*) AS a FROM auth_subject_areas_mapping),
    bcount AS (SELECT count(*) AS b FROM auth_subject_areas_mapping_old)
SELECT a = b FROM acount, bcount;
  • Related