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 7075529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:11:18+00:00 2026-05-28T06:11:18+00:00

I was thinking a way to using one query with a subquery instead of

  • 0

I was thinking a way to using one query with a subquery instead of using two seperate queries.

But turns out using a subquery is causing multiple requests for each row in result set. Is there a way to limit that count subquery result only one with in a combined query ?

SELECT `ad_general`.`id`, 
    ( SELECT  count(`ad_general`.`id`) AS count 
        FROM (`ad_general`) 
        WHERE `city` = 708 ) AS count, 
  FROM (`ad_general`) 
  WHERE `ad_general`.`city` =  '708' 
  ORDER BY `ad_general`.`id` DESC
  LIMIT 15

May be using a join can solve the problem but dunno how ?

  • 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-28T06:11:19+00:00Added an answer on May 28, 2026 at 6:11 am
    SELECT ad_general.id, stats.cnt
    FROM ad_general
      JOIN (
          SELECT count(*) as cnt
            FROM ad_general
            WHERE city = 708
        ) AS stats
    WHERE ad_general.city = 708
    ORDER BY ad_general.id DESC
    LIMIT 15;
    

    The explicit table names aren’t required, but are used both for clarity and maintainability (the explicit table names will prevent any imbiguities should the schema for ad_general or the generated table ever change).

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

Sidebar

Related Questions

This recent question about sorting randomly using C# got me thinking about the way
I have been thinking about the optimal way to create an XML file using
So I was thinking one way that you can bring method chaining into PHP
Maybe I'm thinking about this the wrong way but here's the idea: Class A
I have been thinking about a neat way of load balancing and one thing
I'm thinking which way to go and can't decide which one is better. Maybe
As I've increasingly absorbed Agile thinking into the way I work, yagni (you aren't
I'm curious How do you people think ? (I mean a way of thinking)
Just thinking about the best way to build an Order form that would (from
I'm thinking if there is a way to use javascript to pick up ANY

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.