Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3791686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:30:27+00:00 2026-05-19T12:30:27+00:00

Mysql, I am using SQL_CALC_FOUND_ROWS to get the total number of possible records. How

  • 0

Mysql, I am using SQL_CALC_FOUND_ROWS to get the total number of possible records.
How do I use it on UNION?
The only thing that works for me right now, which seems somewhat off is:

SELECT COUNT(*)
FROM(SELECT * FROM t1 UNION SELECT * FROM t2) A;

or

SELECT SQL_CALC_FOUND_ROWS *
FROM(SELECT * FROM t1 UNION SELECT * FROM t2) A;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:30:28+00:00Added an answer on May 19, 2026 at 12:30 pm

    From the FOUND_ROWS() documentation:

    The use of SQL_CALC_FOUND_ROWS and
    FOUND_ROWS() is more complex for UNION
    statements than for simple SELECT
    statements, because LIMIT may occur at
    multiple places in a UNION. It may be
    applied to individual SELECT
    statements in the UNION, or global to
    the UNION result as a whole.

    The intent of SQL_CALC_FOUND_ROWS for
    UNION is that it should return the row
    count that would be returned without a
    global LIMIT. The conditions for use
    of SQL_CALC_FOUND_ROWS with UNION are:

    • The SQL_CALC_FOUND_ROWS keyword must
      appear in the first SELECT of the
      UNION.

    • The value of FOUND_ROWS() is exact
      only if UNION ALL is used. If UNION
      without ALL is used, duplicate removal
      occurs and the value of FOUND_ROWS()
      is only approximate.

    • If no LIMIT is present in the UNION,
      SQL_CALC_FOUND_ROWS is ignored and
      returns the number of rows in the
      temporary table that is created to
      process the UNION.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you use enums in Oracle using SQL only? (No PSQL) In MySQL
I just read about mysql's SQL_CALC_FOUND_ROWS and FOUND_ROWS() which helps you get the total
How to get the maxmum date and minimum date in mysql using only one
everybody using mysql knows: SELECT SQL_CALC_FOUND_ROWS ..... FROM table WHERE ... LIMIT 5, 10;
Using SQL (MySQL) only I would like to select each of the last child
Here's my table right now (using mysql): SQL Table: koko_table name varchar(140) status varchar(140)
Although I am using mySQL (for now), I dont want any DB specific SQL.
So I have an SQL dump file that needs to be loaded using mysql_query().
I am trying to copy data from my MYSQL table to SQL Server using
I'm trying to make Cakephp paginate take advantage of the SQL_CALC_FOUND_ROWS feature in mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.