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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:52:36+00:00 2026-06-15T08:52:36+00:00

I have a query I am trying to convert to mysql. Here is the

  • 0

I have a query I am trying to “convert” to mysql. Here is the query:

select top 5 * 
from
   (select id, firstName, lastName, sum(fileSize) as TotalBytes, sum(fileSize)/count(b.*)  as Average
    from roster_cs368 a
    join htmp_cs3868 b on b.id =  a.id
)
union
(
    select id, firstName, lastName, sum(fileSize) as TotalBytes, sum(fileSize)/count(b.*) as Average
    from roster_cs368 a
    join atmp_cs3868 b on b.id = a.id
)
order by TotalBytes desc

I am hoping someone can show me the “mysql: way of doing it. I really appreciate it. This is part of a Java program I am doing and not very familiar with sql queries as of yet.

UPDATE:

mysql> select * from roster_cs368
-> ;
+--------+-----------+-----------+
| id     | firstName | lastName  |
+--------+-----------+-----------+
| apn7cf | Allen     | Newton    |
| atggg3 | andrew    | goebel    |
| aysfgd | Alfred    | Santos    |
| cdq6c  | chris     | declama   |

where “id” is the primary key

mysql> select * from htmp_cs368;
+------------+----------+------------+----------+----------+-------+------+-------+----------------------+
| filePerms  | numLinks | id         | idGroup  | fileSize | month | day  | time  | fileName             |
+------------+----------+------------+----------+----------+-------+------+-------+----------------------+
| drwx------ |        2 | schulte    | faculty  |      289 | Nov   |    7 | 2011  | Java                 |
| -rw-r--r-- |        1 | schulte    | faculty  |      136 | Apr   |   29 | 2012  | LD                   |
| drwxr-xr-x |        3 | schulte    | faculty  |      177 | Mar   |   20 | 2012  | Upgrade              |

no primary key here,
and the last table:

mysql> select * from atmp_cs368;
+------------+----------+--------------+----------+----------+-------+------+-------+-----------------------------+
| filePerms  | numLinks | id           | idGroup  | fileSize | month | day  | time  | fileName                    |
+------------+----------+--------------+----------+----------+-------+------+-------+-----------------------------+
| drwxr-xr-x |        2 | remierm      | 203      |      245 | Sep   |   17 | 14:40 | 148360_sun_studio_12        |
| drwx---rwx |       31 | antognolij   | sasl     |     2315 | Oct   |   24 | 12:28 | 275                         |
| -rwx------ |        1 | kyzvdb       | student  |       36 | Sep   |   19 | 13:05 | 275hh                       |
| drwx---rwx |       26 | antognolij   | sasl     |     1683 | Nov   |   12 | 14:00 | 401                         |

no primary key here either.

The query I am to answer is:

produce a list of the five members of roster_cs368
and their ids who use the most space (number of bytes)
in htmp_cs368 and atmp_cs368 in descending order--
greediest first.

Hope this info helps. Please note, there is much more information in the tables then presented. What is here is just a snippet.

  • 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-15T08:52:37+00:00Added an answer on June 15, 2026 at 8:52 am

    As documented under SELECT Syntax:

    The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement.

    Therefore:

    (
      SELECT id,
             firstName,
             lastName,
             SUM(fileSize) AS TotalBytes,
             SUM(fileSize)/COUNT(*) AS Average
      FROM   roster_cs368 AS a
        JOIN htmp_cs3868  AS b USING (id)
    ) UNION (
      SELECT id,
             firstName,
             lastName,
             SUM(fileSize) AS TotalBytes,
             SUM(fileSize)/COUNT(*) AS Average
      FROM   roster_cs368 AS a
        JOIN atmp_cs3868  AS b USING (id)
    )
    ORDER BY TotalBytes DESC
    LIMIT 5
    

    Note that id, firstName and lastName are hidden columns, the values of which are indeterminate unless the same for every record.

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

Sidebar

Related Questions

Here's an example of the query I'm trying to convert to LINQ: SELECT *
questions from a Newbie :-) I am trying to convert my MySQL query syntax
I have a following query: SELECT users.user_id as user_id , users.USERNAME, users.FIRSTNAME, users.LASTNAME, roles.name
I have folowing MYsql Query And Trying to right outer join but unable to
I have a problem with this query trying to get a sum and a
I have the SQL and trying to convert ti to Linq query. I need
I have a query in SQL Server that I am trying to convert to
So I have a SQL Query as Follows SELECT P.Date, P.CategoryName, P.ProductName, SUM(Quantity) Quantity,
I'm trying to convert this linq query to lambda var query = (from a
I am trying to convert a Linq query that I have working in Linq

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.