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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:44:58+00:00 2026-06-11T14:44:58+00:00

I have such a schema and queries: http://sqlfiddle.com/#!2/7b032/3 Seperately I have these queries: SELECT

  • 0

I have such a schema and queries:
http://sqlfiddle.com/#!2/7b032/3

Seperately I have these queries:

SELECT COUNT(*) AS 'times', userid, name
FROM main
WHERE comedate <= DATE_SUB(CURDATE(),
                   INTERVAL 5 DAY)
GROUP BY userid ORDER BY times DESC LIMIT 0,2;

SELECT * FROM details WHERE 1;

By comparing userid columns of both table I need to join them.
I need an output having these columns:
“times, userid, name, age, location“
Also order, group and limits should be considered.

I would be happy if you can write one query with JOIN and one query with subquery.
I have a 60k table and I will compare the performances.

  • 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-11T14:44:59+00:00Added an answer on June 11, 2026 at 2:44 pm

    How about this:

    select x.times,
      x.userid,
      x.name,
      d.age,
      d.location
    from 
    (
      SELECT COUNT(*) AS 'times', userid, name
      FROM main
      WHERE comedate <= DATE_SUB(CURDATE(),
                         INTERVAL 5 DAY)
      GROUP BY userid 
    ) x
    left join details d
      on x.userid = d.userid
    

    see SQL Fiddle with Demo

    edit:

    select x.times,
      x.userid,
      x.name,
      d.age,
      d.location
    from 
    (
      SELECT COUNT(*) AS 'times', userid, name
      FROM main
      WHERE comedate <= DATE_SUB(CURDATE(),
                         INTERVAL 5 DAY)
      GROUP BY userid
      ORDER BY times DESC 
      LIMIT 0,2
    ) x
    left join details d
      on x.userid = d.userid
    

    see SQL Fiddle with demo

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

Sidebar

Related Questions

I have an xml string such as this: <s:Envelope xmlns:s=http://schemas.xmlsoap.org/soap/envelope/> <s:Body> <ExecuteResponse xmlns=http://schemas.microsoft.com/xrm/2011/Contracts/Services> <ExecuteResult
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have such file and I would like to replace $GLOBALS['SERVER_MEMCACHED']='localhost'; with $GLOBALS['SERVER_MEMCACHED']='mydomain.com'; using
Say you have a table schema such as this: friends(friendship_id, uid1, uid2, are_friends) .
I have some table with such schema (simplified): CREATE TABLE folders( id INT(11) UNSIGNED
I have an XSD file such as: <xs:schema targetNamespace=...> <xs: import namespace=...> <xs: import
i have such code (copy paste from wiki). Its multiplication of those big numbers
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
i have such function to solve some logic riddle iloczyny is list with such
I have such a grid square disk. Every grid represents a pixel. My aim

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.