I want to compare row count of two tables and then return 0
or 1
depending on whether its same or not.
I am thinking of something like this but can't move ahead and need some help.
SELECT
CASE WHEN (select count(*) from table1)=(select count(*) from table2)
THEN 1
ELSE 0
END AS RowCountResult
FROM Table1,Table2
I am getting multiple rows instead of a single row with 0
or 1
SELECT (SELECT count(*) from table1)=(SELECT count(*) from table2) AS RowCountResult; as a boolean result will be returned.
Use the Find Unmatched Query Wizard to compare two tables One the Create tab, in the Queries group, click Query Wizard. In the New Query dialog box, double-click Find Unmatched Query Wizard. On the first page of the wizard, select the table that has unmatched records, and then click Next.
The SQL intersect operator allows us to get common values between two tables or views. The following graphic shows what the intersect does. The set theory clearly explains what an intersect does. In mathematics, the intersection of A and B (A ∩ B) is the set that contains all elements of A that also belong to B.
Here's the SQL query to compare each row with previous row. In the above query, we join sales table with itself using an INNER JOIN condition g2.id=g1.id + 1 that allows you to compare each row with its previous row. Please note, this condition depends on the fact that our id column has consecutive numbers.
you have to remove :
FROM Table1,Table2
Otherwise it will consider the result of the Case-When for each row of this FROM clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With