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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:31:34+00:00 2026-06-13T18:31:34+00:00

This is my database project. table user_ select id, name from user_; id |

  • 0

This is my database project.

table user_

select id, name from user_;

 id |   name
----+----------
  1 | bartek
  2 | bartek_m
  3 | bartek_k
  4 | bartek_b

table order_

select id, employee_id, user_id from order_;

 id | employee_id | user_id
----+-------------+---------
  1 |           3 |       1
  2 |           4 |       1
  3 |           4 |       1
  4 |           4 |       1
  5 |           3 |       1

Every user has a role(I don’t add table role_ here but it exist).
ID of every user with role employee can be assigned to order_.employee_id
I need obtain user with minimum number of orders

select a.id, min(a.count) from (
    select u.id, count(u.id) from user_ u, order_ o
    where u.id = o.employee_id
    group by u.id
) as a group by a.id, a.count

 id | min
----+-----
  4 |   3
  3 |   2

I think that my query is wrong. Could anyone change query to return
only ID this user which have minimum number of orders?

  • 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-13T18:31:35+00:00Added an answer on June 13, 2026 at 6:31 pm

    Like

    SELECT u.id, count(*)
    FROM user_ AS u JOIN order_ AS o ON (u.id=o.employee_id)
    GROUP BY u.id
    ORDER BY 2 LIMIT 1
    

    (if I read you right)?

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

Sidebar

Related Questions

Here's the thing: In my Qt4.6-Project, I use a SQLite-Database. This database shouldn't be
I got a project of designing a Database. This is going to be my
Let's consider this fabfile def syncdb(): print(green(Database Synchronization ...)) with cd('/var/www/project'): sudo('python manage.py syncdb',
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
enter code here My problem is this: in this database the junction table contains
EDIT I'm understand the table is a mess. I took over this project and
I've got a datagridview in my project, which is populated from a SQL database
During my work on this database application, I've apparently managed to corrupt a form
How do I import this database correctly? https://github.com/samanz/cakecart Every time I import then I
I have a production database where usage statistics reside. This database is responsible for

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.