SELECT COUNT(*) FROM (
SELECT 1 FROM ...
UNION SELECT 1 FROM ...
UNION SELECT 1 FROM ...
) as tmp_table
Despite the result set including multiple rows, COUNT(*) will always return 1… why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
UNION SELECTautomatically groups your results, meaning that you will not see duplicate rows. What you need isUNION ALL SELECT..., then your results will not be grouped and you will see duplicate rows.Duplicate rows meaning, because you always select 1, so it groups by 1.