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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:51:04+00:00 2026-05-27T19:51:04+00:00

Table 1 person_id| location_id | field a | field b |friend_id Table 2 location_id

  • 0

Table 1

person_id| location_id | field a | field b |friend_id

Table 2

location_id | location_name

friend_id is the id of a person liked by the given person ( it’s an optional field and the default value is zero )

How can I query the two tables to get the following :

the location_name of the person who has been liked by the maximum people and so on in decreasing order.

  • 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-27T19:51:04+00:00Added an answer on May 27, 2026 at 7:51 pm

    First, ensure you have an index on the Friend_ID column so it can be optimized in the query

    select
          P.Person_ID,
          P.FieldA,
          P.FieldB,
          L.Location_Name,
          ByPopularity.Popular
       from
          ( select T1.friend_id, count(*) as Popular
               from Table1 T1
               group by T1.friend_id
               order by Popular DESC ) ByPopularity
    
             JOIN Table1 P
                on ByPopularity.Friend_ID = P.person_ID
    
                Join Table2 L
                   on P.Location_ID = L.Location_ID
    

    EDIT — PER COMMENT on how to get most popular location based on people originations

    select
          L.Location_Name,
          ByPopularity.PopularLocation
       from
          ( select T1.Location_ID, count(*) as PopularLocation
               from Table1 T1
               group by T1.Location_ID
               order by PopularLocation DESC ) ByPopularity
    
               Join Table2 L
                   on ByPopularity.Location_ID = L.Location_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables like this: Person table: person_id | name | dob --------------------------------
I have a table with two columns: person_id person_id with whom 1st field id
Steps to reproduce error: CREATE TABLE person ( person_id int(11) NOT NULL AUTO_INCREMENT, firstname
Given the following tables stored in SQL database Table person id username phone 1
How do I implement the following relationship using JPA? table person ( id int,
imaging i have 3 tables, person, boy, girl table person{ id ...} table boy{
My table looks like person_id | car_id | miles ------------------------------ 1 | 1 |
I have three tables Person (id, name, email) Address (id, Person_id, address, verified) Person_Claimed
My Entity Model is as follows: Person , Store and PersonStores Many-to-many child table
I’d like to list all the people ( Person table ) that don’t live

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.