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

  • Home
  • SEARCH
  • 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 8534625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:14:19+00:00 2026-06-11T10:14:19+00:00

I have a STUDENT table which contains data about students from a faculty: STUDENT(ID,

  • 0

I have a STUDENT table which contains data about students from a faculty:

STUDENT(ID, Name, Grade, ID_Tutor)

Structure and data:

CREATE TABLE STUDENT
    (`ID` int, `Name` varchar(5), `Grade` int, `ID_Tutor` int);

INSERT INTO STUDENT
    (`ID`, `Name`, `Grade`, `ID_Tutor`)
VALUES
    (1,    'A',     10,       NULL),
    (2,    'B',     9.5,      1),
    (3,    'C',     9,        1),
    (4,    'D',     8,        1),
    (5,    'E',     7,        4),
    (6,    'F',     8,        1),
    (7,    'G',     5,        7),
    (10,   'H',     6,        5)
    (11,   'I',     7,        3),
    (12,   'J',     9,        10),
    (13,   'K',     9.6,      11),
    (14,   'L',     8.9,      5),
    (15,   'M',     9.9,      13),
    (16,   'N',     7,        2),
    (17,   'O',     7.9,      2),
    (18,   'P',     2,        15);

Top 5 faculty grades:

    `ID`, `Name`, `Grade`, `ID_Tutor`
    (1,    'A',     10,       NULL),
    (15,   'M',     9.9,      13),
    (13,   'K',     9.6,      11),
    (2,    'B',     9.5,      1),
    (3,    'C',     9,        1),
    (12,   'J',     9,        10),

In result should appear students with these tutors from the above table.

I want to make a SQL query (MYSQL) to find

  • student name,
  • tutor name and
  • tutor grade

for students whose tutor has a grade in top 5 faculty students (and without using LIMIT and/or ROWNUM – for a Oracle solution).

Result should look like this:

| student name | tutor name | tutor grade |
       'B'           'A'          10           
       'C'           'A'          10           
       'D'           'A'          10           
       'F'           'A'          10           
       'P'           'M'           9.9           
       'M'           'K'           9.6              
       'N'           'B'           9.5            
       'O'           'B'           9.5            
       'I'           'C'           9            

I tried something like this (but not working) and I think I’m complicating a lot… (and I should not use ROWNUM)

SELECT 
    s.ID, 
    s.Name Student, 
    s.Grade, 
    p.ID_Tutor, 
    p.Grade
FROM 
    STUDENT s,
    (SELECT * FROM 
        (SELECT * FROM 
            (SELECT 
                t.Name Tutor , 
                t.ID , 
                Grade Grade_Tutor 
            FROM STUDENT s
                JOIN STUDENT t 
                    on s.ID_Tutor = t.ID
            GROUP BY t.Name, t.ID)
        ORDER BY 3 desc ) 
    WHERE ROWNUM < 6) p
WHERE s.ID_Tutor = p.ID

Give me this error:

    #1248 - Every derived table must have its own alias

Thanks in advance!

  • 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-11T10:14:20+00:00Added an answer on June 11, 2026 at 10:14 am

    Many thanks to @TehShrike, is his answer!!!

    The only “downside” is that is using LIMIT, but if someone has a version without LIMIT please post it; until then, thanks again, @TehShrike!

    SELECT 
            student.NAME AS student_name, 
            top_five_tutors.NAME AS tutor_name, 
            top_five_tutors.grade AS tutor_grade
    FROM (
            SELECT 
                    tutor.id, 
                    tutor.NAME, 
                    tutor.Grade
            FROM (
                    SELECT DISTINCT 
                                    id_tutor AS id
                    FROM student
                 ) AS tutor_ids
    
            JOIN student AS tutor 
                ON tutor.id = tutor_ids.id
    
            ORDER BY tutor.grade DESC
                LIMIT 5
         ) AS top_five_tutors
    
    JOIN student 
        ON student.id_tutor = top_five_tutors.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named Grades which contains 2 columns: Name and Grade. I
i have a table named students which have student details id,mark,name i want to
i have a table Students which contains the following colums: Id,FirstName,LastName,Adress . The colum
I have a database Student which contains about 20 tables. one of the tables
i have a table which consists of student details like roll no, Name, age.
I have a table which contains student grades (SAG). I need to show all
I have a Student table which should have name column. But I made another
In MySQL, I have a Student Table which contains a StudnetId column which goes
I have a table called student which I want to populate from the server.
I have an attendance table which contains student's attendance date and attendance status. Is

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.