0

I have five tables as listed below.

Question: is it possible to join all five tables and output the result as show below?

<table>
    <tr>
        <th>Subject</th>
        <th>Last update (date from table. nr.3)</th> 
        <th>Last update (date from table. nr.4)</th>
        <th>Last update (date from table. nr.5)</th>
    </tr>
    <tr>
        <td>Mathematics</td>
        <td>2014-06-01</td>
        <td>2014-07-05</td>
        <td>2014-03-15</td>
    </tr>
    <tr>
        <td>English</td>
        <td>2014-01-01</td>
        <td>2014-02-11</td>
        <td>2014-04-21</td>
    </tr>
    <tr>
        <td>German</td>
        <td>2014-01-02</td>
        <td>2014-05-30</td>
        <td>2014-07-03</td>        
    <tr>   
</table>

Table (containing subject id and subject name)

 CREATE TABLE IF NOT EXISTS `subject` (
      `subject_id` int(3) NOT NULL AUTO_INCREMENT,
      `subject_name` varchar(50) COLLATE utf8_swedish_ci NOT NULL,
      PRIMARY KEY (`amne_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci AUTO_INCREMENT=100 ;

Table (containing subjects that not will be read current semester)

    CREATE TABLE IF NOT EXISTS `reading_subject` (
      `read_id` int(5) unsigned NOT NULL AUTO_INCREMENT,
      `class` varchar(3) COLLATE utf8_swedish_ci NOT NULL,
      `subject_id` int(3) NOT NULL,
      `semester` varchar(2) COLLATE utf8_swedish_ci DEFAULT NULL,
       PRIMARY KEY (`read_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci AUTO_INCREMENT=25 ;

Table (nr. 3, containing information regarding each assessment)

    CREATE TABLE IF NOT EXISTS `kunskapskrav_klick` (
      `kun_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `subject_id` int(3) NOT NULL,
      `student_id` int(3) NOT NULL,
      `teacher_id` int(3) NOT NULL,
      `semester` varchar(2) COLLATE utf8_swedish_ci NOT NULL,
      `date_a` date NOT NULL,
      PRIMARY KEY (`kun_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci AUTO_INCREMENT=45699 ;

Table (nr.4, containing assessment from teacher)

CREATE TABLE IF NOT EXISTS `assess_teacher` (
  `kuns_id_teacher` int(10) NOT NULL AUTO_INCREMENT,
  `subject_id` int(3) NOT NULL,
  `student_id` int(10) NOT NULL,
  `teacher_id` int(3) NOT NULL,
  `semester` varchar(25) COLLATE utf8_swedish_ci NOT NULL,
  `date` varchar(25) CHARACTER SET latin1 NOT NULL DEFAULT '',
   PRIMARY KEY (`kuns_id_teacher`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci AUTO_INCREMENT=7560 ;

Table (nr.5, containing text from student)

 CREATE TABLE IF NOT EXISTS `assess_student` (
      `kuns_id_student` int(10) NOT NULL AUTO_INCREMENT,
      `subject_id` int(3) NOT NULL,
      `student_id` int(3) NOT NULL,
      `teacher_id` int(3) NOT NULL,
      `date` date NOT NULL,
    PRIMARY KEY (`kuns_id_student`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci AUTO_INCREMENT=6142 ;
3
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by diafol
0

As long as each table has one column which refers it to another table, through which a linkage can be made, you can join them all.
It doesn't need to be the same column in all tables as long as a chain of connectivity can be made.
In your case it looks like you can use teacher_id/teacher_id to refer to most of the tables and subject_id to link to the subjects table.

0
SELECT ...fields... FROM firstTableName AS Alias1 
    INNER JOIN secondTableName AS Alias2 ON Alias1.fieldX = Alias2.fieldY
    INNER JOIN thridTableName AS Alias3 ON Alias2.fieldG = Alias3.fieldK ...

You just keep adding (inner) join/on clauses

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.