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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:36:50+00:00 2026-06-12T22:36:50+00:00

Table Structure id | term | result ================== 1 | t1 | 0 2

  • 0

Table Structure

id | term | result
==================
1  | t1   | 0
2  | t2   | 0
3  | t1   | 34
4  | t1   | 23
5  | t2   | 10
6  | t2   | 10
7  | t3   | 20

The table is for a search table where term is the keyword someone was searching for, and result is the number of results returned at that time. Now from this table I need to retrieve
1) number of times a term was searched for and
2) the number of results that were returned when it was last search for.

for the first one I can do count(term) group by term, and for 2 probably ORDER by id DESC, but I don’t know how to do both in a single query. Any help?

  • 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-12T22:36:52+00:00Added an answer on June 12, 2026 at 10:36 pm

    You want the groupwise maximum:

    SELECT term, count, result
    FROM   my_table NATURAL JOIN (
             SELECT term, COUNT(*) count, MAX(id) id FROM my_table GROUP BY term
           ) t
    

    See it on sqlfiddle.

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

Sidebar

Related Questions

Table structure: country season points Current query: SELECT SUM(points) AS total, country FROM table
Table structure id (p) | date | id2 (fk) | id3 (fk) where (p)
Table structure- int PrimaryKey DateTime Date int Price What I would like to do
Table structure goes something like this: Table: Purchasers Columns: id | organization | city
My table structure is below: CREATE TABLE [ACC].[Document]( [DocumentID] [int] IDENTITY(1,1) NOT NULL, [Date]
My table structure is below : MyTable (ID Int, AccID1 Int, AccID2 Int, AccID3
My table structure in the database; Table System_t id | Owner | System ===========================================
My table structure is: TABLE `licenses` ( `id` int(11) NOT NULL auto_increment, `code` varchar(30)
Simplified Table structure: CREATE TABLE IF NOT EXISTS `hpa` ( `id` bigint(15) NOT NULL
My table structure looks like : Account AccountId LoginName EmployeeId - nullable Employee FirstName,

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.