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

The Archive Base Latest Questions

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

Is this the most efficient way of joining these 4 tables? Also is it

  • 0

Is this the most efficient way of joining these 4 tables? Also is it possible to only have some rows of each tables selected? I tried changing * to a name of a column but only the columns from studentlist are allowed.

SELECT c.classID, c.instrument, c.grade, u.ID, u.firstname, u.lastname, u.lastsongplayed, u.title
FROM studentlist s
INNER JOIN classlist c ON s.listID = c.classID
INNER JOIN (

SELECT * 
FROM users u
INNER JOIN library l ON u.lastsongplayed = l.fileID
)

u ON s.studentID = u.ID
    WHERE teacherID =3
    ORDER BY classID
    LIMIT 0 , 30

Database structure:

CREATE TABLE IF NOT EXISTS `classlist` (
  `classID` int(11) NOT NULL AUTO_INCREMENT,
  `teacherID` int(11) NOT NULL,
  `instrument` text,
  `grade` int(11) DEFAULT NULL,
  PRIMARY KEY (`classID`),
  KEY `teacherID_2` (`teacherID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=27 ;


CREATE TABLE IF NOT EXISTS `studentlist` (
  `listID` int(11) NOT NULL,
  `studentID` int(11) NOT NULL,
  KEY `teacherID` (`studentID`),
  KEY `studentID` (`studentID`),
  KEY `listID` (`listID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(60) NOT NULL,
  `password` varchar(60) NOT NULL,
  `firstname` text NOT NULL,
  `lastname` text NOT NULL,
  `sessionID` varchar(60) DEFAULT NULL,
  `lastlogin` time DEFAULT NULL,
  `registerdate` date NOT NULL,
  `isteacher` tinyint(1) DEFAULT NULL,
  `isstudent` tinyint(1) DEFAULT NULL,
  `iscomposer` tinyint(1) DEFAULT NULL,
  `lastsongplayed` int(11) NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID` (`ID`),
  UNIQUE KEY `email` (`email`,`sessionID`),
  KEY `ID_2` (`ID`),
  KEY `ID_3` (`ID`),
  KEY `lastsongplayed` (`lastsongplayed`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;

CREATE TABLE IF NOT EXISTS `library` (
  `fileID` int(11) NOT NULL AUTO_INCREMENT,
  `userID` int(11) NOT NULL,
  `uploaddate` datetime NOT NULL,
  `title` varchar(60) NOT NULL,
  `OrigComposer` varchar(60) NOT NULL,
  `composer` varchar(60) NOT NULL,
  `genre` varchar(60) DEFAULT NULL,
  `year` year(4) DEFAULT NULL,
  `arrangement` varchar(60) DEFAULT NULL,
  PRIMARY KEY (`fileID`),
  KEY `userID` (`userID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=77 ;
  • 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:58:15+00:00Added an answer on June 15, 2026 at 8:58 am

    Is this the most efficient way of joining these 3 tables?

    Your JOIN looks correct and you are joining on your keys. So this should be efficient. However, I would encourage you to analyze your query with EXPLAIN to determine additional optimizations.

    Is it possible to only have some rows of each tables selected?

    Yes. Change * to be the columns from each table you want. I encourage you to explicitly prefix them with the originating table. Depending on the columns you select, this could also make your query more performant.

    SELECT studentlist.studentID, users.email FROM ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string: B82V16814133260 what would be the most efficient way to get
I am trying to do this the most efficient way possible. Think of Apple's
I know I am probably not doing this the most efficient way. I have
Is this the most efficient way to retrieve these xml elements using php? It
What is the most efficient way to do this? Right now I am doing
What's the most efficient way to remove the text 2010-04-07 14:25:50,773 DEBUG This is
hey all. Just wanting to know is this the most efficient way of getting
If I have five variables int a,b,c,d,e; What is the most efficient way to
I was just wondering if this is the most efficient way to use categories:
I have two tables, one table has some information in each row along with

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.