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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:47:11+00:00 2026-06-04T05:47:11+00:00

I am using this query: SELECT district, id FROM adverts ls GROUP BY district,

  • 0

I am using this query:

SELECT district, id
FROM adverts ls
GROUP BY district, id
HAVING (

SELECT count( * )
FROM adverts
WHERE district = ls.district
AND id > ls.id
) <5
ORDER BY district, id DESC ;

LIMIT 0 , 30

It tooks about 35 seconds. Here is the explanation:

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   PRIMARY     ls  range   NULL    i_id    5   NULL    16166   Using index for group-by; Using temporary; Using f...
2   DEPENDENT SUBQUERY  ilan_genel  ref     PRIMARY,i_id,i_ozellik_id,i_tip_fiyat,i_tip_id,i_d...   i_durum_id  2   func    25  Using where; Using index 

Is there a way to make it faster ?

  • 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-06-04T05:47:13+00:00Added an answer on June 4, 2026 at 5:47 am

    try this:

    SELECT    district, id, COUNT(b.district)
    FROM      adverts a INNER JOIN adverts b
                  ON a.district = b.district
    WHERE     b.id > a.id
    GROUP BY  district, id 
    HAVING    COUNT(b.district) < 5
    ORDER BY  district, id DESC 
    

    by definition, Joins are faster than subqueries.

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

Sidebar

Related Questions

I am using this query: SELECT * from likes GROUP BY url ORDER BY
i tried using this query: SELECT * FROM guests WHERE event_id=.$id. GROUP BY member_id;
I'm using this query to list duplicate records SELECT DISTINCT column1 from table group
I am using This JPA-Query: SELECT DISTINCT e.label FROM Entity e GROUP BY e.label
I am using this query SELECT COUNT(DISTINCT to_number) AS errors FROM sent_txts WHERE msg_link_id
I am using this query: SELECT p.id, count(clicks.ip) FROM `p` LEFT JOIN c clicks
I am using this query: SELECT DISTINCT pat.PublicationID FROM dbo.PubAdvTransData AS pat INNER JOIN
When using this SQL query: Select * from table_name what happens if the name
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
Im using this query: SELECT `projects`.*, (SELECT SUM(`amount`) FROM `accountprojectspayment` WHERE `projects_id` = `projects`.`id`)

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.