tomhath: you saved my day. To be honest I really doubted this could be done, but well, thanks for proving me wrong. I had written an exact description of my problem before I saw your reply, and it took me a bit of time to do it, so I'm just gonna let it go 🙂
The following queries might have minor errors, I had to translate the names of the tables to english to make their purpose more understandable.
CREATE TABLE classes_info (
id smallint(4) unsigned NOT NULL auto_increment,
strClassname varchar(200) NOT NULL default '',
strDescription text,
intInstructor1 smallint(5) unsigned NOT NULL default '0',
intInstructor2 smallint(5) unsigned default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM
CREATE TABLE instructors (
id smallint(5) unsigned NOT NULL auto_increment,
strNickname varchar(30) NOT NULL default '',
strFullname varchar(50) NOT NULL default '',
strEmail varchar(60) default NULL,
strPhone varchar(7) default NULL,
strInfo text,
PRIMARY KEY (id)
) TYPE=MyISAM
CREATE TABLE timetable (
id smallint(5) unsigned NOT NULL auto_increment,
intWeekday tinyint(1) unsigned NOT NULL default '0',
timeTimiStart time NOT NULL default '00:00:00',
timeTimiEnd time NOT NULL default '00:00:00',
intClass smallint(4) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM
INSERT INTO instructors (strNickname,strFullname,strEmail,strPhone,strInfo) VALUES ('Johnny','John Doe','john@threk.is','5555555','John is one of our best staff member ...');
INSERT INTO instructors (strNickname,strFullname,strEmail,strPhone,strInfo) VALUES ('Joan','Joan Doe','joan@threk.is','5556666,'Joan is the worst staff member');
insert into classes_info(strClassname,strDescription,intInstructor1,intInstructor2) VALUES ('Jogging','Jogging around','1,2);
INSERT INTO timetable (intWeekday,timTimiStart,timeTimiEnd, intClass) values (1,'08:00','09:10',1);
means: (Monday,time-starts-at-0800,time-ends-at-0910,refers-to-id-in-classes_info)
okay, if I would only have 1 instructor, the query would look like this:
SELECT
timetable.intWeekday,
CONCAT(time_format('%H:%i',timeTimiStart),'-',time_format('%H:%i',timeTimiEnd)) as timerange,
classes_info.strClassname,
instructors.strNickname
FROM
timetable
LEFT JOIN
classes_info ON
timetable.intClass = classes_info.id
LEFT JOIN
instructors ON
classes_info.intInstructor1 = instructors.id;
the results of the query would look like this somehow:
+----------+-----------+------------+-----------+
|intWeekday|timerange |strClassname|strNickname|
+----------+-----------+------------+-----------+
| 1|08:00-09:10| Jogging| Johnny|
+----------+-----------+------------+-----------+
when my desired results would look like this:
+----------+-----------+------------+-----------+------------+
|intWeekday|timerange |strClassname|strNickname|strNickname2|
+----------+-----------+------------+-----------+------------+
| 1|08:00-09:10| Jogging| Johnny| Joan|
+----------+-----------+------------+-----------+------------+
SO following tomhath's advice, the query looks like this:
SELECT
timetable.intWeekday,
CONCAT(time_format('%H:%i',timeTimiStart),'-',time_format('%H:%i',timeTimiEnd)) as timerange,
classes_info.strClassname,
in1.strNickname as instr1
in2.strNickname as instr2
FROM
timetable
LEFT JOIN
classes_info ON
timetable.intClass = classes_info.id
LEFT JOIN
instructors in1 ON
classes_info.intInstructor1 = instructors.id
LEFT JOIN
instructors in2 ON
classes_info.intInstructor2 = instructors.id
.... just hope someone else can learn from this.