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

  • Home
  • SEARCH
  • 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 6576885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:02+00:00 2026-05-25T15:34:02+00:00

This is how I have my current query setup: SELECT * , ( SELECT

  • 0

This is how I have my current query setup:

SELECT * , (    
SELECT COUNT( * ) 
FROM paintings
WHERE id > 4000
) AS total
FROM paintings
WHERE id > 4000
LIMIT 0 , 30

Everything works fine if I separate the queries but if I keep it like this the pagination shows 1 id missing at the end of the page.

What would be a better option for selecting count that doesn’t return on each row but for the whole?

Ex: this is what I currently get if I pass that in mysql:

> +--------+------------+--------+
> |  id    | title      | count  |
> +--------+------------+--------+
> | 2345   | water      |   25   | 
> | 2346   | bread      |   25   | 
> | 2347   | coke       |   25   | 
> | 2348   | beer       |   25   | 
> | 2349   | oranges    |   25   | 
> +--------+------------+--------+

Cheers!

  • 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-25T15:34:02+00:00Added an answer on May 25, 2026 at 3:34 pm

    Addition to what genesis posted. Still 2 queries but a little cleaner:

    # The main query
    SELECT SQL_CALC_FOUND_ROWS * FROM paintings
    WHERE id > 4000
    LIMIT 0, 30;
    
    # And after get the total
    SELECT FOUND_ROWS() AS total;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this query set-up: SELECT topic.content_id, topic.title, image.location FROM mps_contents AS topic
I have this query: SELECT TO_CHAR(HON.CREATE_DT,'DD-MM-YYYY') as CREATE_DT, HON.ACCOUNT_NO,(SELECT TO_CHAR(CURRENT_DATE - INTERVAL '7' DAY,
I have this code: Dim pathString As String = HttpContext.Current.Request.MapPath(Banking.mdb) Dim odbconBanking As New
If I understand this correctly: Current CPU developing companies like AMD and Intel have
I have this setup where in my development copy I can commit changes on
I have this procedure used for getting items on the current page. I would
I have a pretty big query to pull out the information about reports from
I want to combine the following queries into a single query: SELECT val FROM
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
Has anyone done this / have some example code?

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.