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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:53:18+00:00 2026-05-22T16:53:18+00:00

I have to come and ask this because I’m already angry and crying and

  • 0

I have to come and ask this because I’m already angry and crying and everything, because this really kills me. I hate SQL. But it has to be done. Website uses SQL.

I have these tables (shortened to the necessessary and not real SQL):

CREATE TABLE deliverer(d_id INT PRIMARY KEY, name VARCHAR(80));
CREATE TABLE article(a_id INT PRIMATY KEY, brand VARCHAR(80));
CREATE TABLE delivers(d_id FOREIGN KEY(deliverer), a_id FOREIGN KEY(article));

I need, for each brand those deliverers that deliver the most articles. I’ve come as far as this, after only two hours of mind twisting:

SELECT brand, MAX(cnt)
FROM
(SELECT COUNT(a.a_id) AS cnt, a.brand, d.d_id, d.name
    FROM derliverer d, delivers l, article a
    WHERE a.a_id = l.a_id AND l.d_id = d.d_id
    GROUP BY a.brand, d.d_id, d.name)
GROUP BY brand;

What I really, really, really don’t get about SQL is why it does not let me GROUP BY brand and SELECT the d.name, d.d_id. It really makes no sense.

Please help me before I jump out of the window.

  • 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-22T16:53:19+00:00Added an answer on May 22, 2026 at 4:53 pm

    What I really, really, really don’t get about SQL is why it does not let me GROUP BY brand and SELECT the d.name, d.d_id. It really makes no sense.

    Because if you do, the count will be for each distinct d.name, d.d_id. This is not what you want.

    You definitely want to read some tutorials on how a group by works.

    I need, for each brand those deliverers that deliver the most articles.

    In this case you need something like:

    select brand_id, count(*) as top_deliverer, deliverer_id, deliverer.etc.
    from some stuff
    group by brand_id, deliverer_id, deliverere.etc
    order by top_deliverer desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is has already been ask but I can't find the exact
I have come across loop-unrolling but what other types of compiler optimization are there
So, I've come back to ask, once more, a patterns-related question. This may be
I'm going to preface with: I hope I can ask this question here, because
this problem has been on my mind for so long, I have not come
I'm hesitant to ask because I'm sure it's out there, but I just can't
I am nearly ashamed to ask this, but... EDIT: I edited the question to
I think many people have come across this problem, You have a 2D array
I have come across an annoying problem. I have made a system and now
I have come to know from book that for declaring a structure variable it

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.