1

I have two different MySQL count queries like this:

SELECT COUNT(*) AS stored_counter FROM users WHERE ***

SELECT COUNT(*) AS total_taken FROM completed WHERE *** 

I'm looking for if the count value of query 1 matches the count value of query 2. Right now I am running these two queries seperately via PHP and then using PHP to see if the two queries return the same values.

But i'm looking to see if it's possible to do this with 1 SQL query?

Thanks

1 Answer 1

1

You can use this form

SELECT
(SELECT COUNT(*)  FROM users WHERE 1 =1) stored_counter,
(SELECT COUNT(*) FROM completed WHERE 1=1)  total_taken

You can add every Select statement that only gives back one Result (one field(one row one column)) only) as its own column

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.