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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:33:15+00:00 2026-06-13T12:33:15+00:00

Here are my three relevant sql tables with their relevant properties: OrderType with property

  • 0

Here are my three relevant sql tables with their relevant properties:

  1. OrderType with property ID
  2. RestaurantVisit, with property OrderTypeID and RestaurantID
  3. Restaurant, with property ID

When given an Order Type (eg Drink, Side, Entree), I need to return all of the restaurants that have ordered that order type before, ordered by which restaurant has the most orders of that type.

For example, given type side, I return Restaurants r1, r2, r3, where r1 is the restaurant that has the most orders of side out of all the restaurants, r2 is the one with second most, etc.

This is what I have so far (remember, I’m given an OrderTypeID already):

SELECT DISTINCT r.ID
FROM Restaurant r
  JOIN RestaurantVisit rv
    ON rv.OrderTypeID = ?
WHERE rv.ID = r.ID

This currently works to return all of the restaurants that have ever received an order of the given type. What I need to do now is order these by the restaurants that have the most of orders of the given type.

What I’m thinking is to add something like this somewhere, but I’m not at all sure:

ORDER BY COUNT(rv.OrderTypeID = ?)

Anyone have any ideas? Thanks!

  • 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-13T12:33:16+00:00Added an answer on June 13, 2026 at 12:33 pm
      SELECT R.ID, R.Name, Count(V.OrderTypeID) NumVisits
        FROM OrderType T
        JOIN RestaurantVisit V on V.OrderTypeID = T.ID
        JOIN Restaurant R on R.ID = V.RestaurantID
       WHERE T.name = 'side'
    GROUP BY R.ID, R.Name
    ORDER BY NumVisits DESC;
    

    The ANSI/ISO standard for ORDER BY is to use the column alias. The (INNER) JOINs will ensure the type has been ordered by the Restaurant before.

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

Sidebar

Related Questions

I have three tables: Employee(EmployeeID,Fname,Lname...) ProjectHeader(ProjectID,LeadID,Status....) ProjectDetails(ProjectDetailsID,ProjectID....) Here's my current code: $get_projects = SELECT
Rails noob here. I have a rails application with (in this example) three tables.
I would like to extract some data from three tables in a SQL Server
I have a fairly simple database consisting of three (relevant) tables: users, permissions, and
Here is the code relevant to my question: http://jsfiddle.net/mkerny45/V23NK/ As you can see there
I am having three arraylist,Here I have to concatenate 2 arraylist and display it
This is a continuation of this question from yesterday . Here are my three
Here are the constraints I have three buckets (water) capacities 10 litre, 2 liters
Here's my scenario: I need to make three or four calls to different WCF
Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on

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.