MySQL Forums
Forum List  »  Newbie

Need help to construct basic query for 3 small tables
Posted by: Nazreen Maula
Date: December 13, 2014 02:24AM

Hello, thanks for reading. I really need help with this code, im new to SQL, this my first time studying it and we're only 10% into the chapters and have got this assignment. I had no problem creating the table but to complete some of the queries, i encountered a couple of problems. perhaps you can help me to solve the questions here.

CREATE TABLE student (
no_matrik INT,
name_student VARCHAR(15),
address VARCHAR(20),
no_tel VARCHAR(15),
course VARCHAR(15))

INSERT INTO student VALUES (12345,'Mazlina','Ampang','012-3842375','DTM')
INSERT INTO student VALUES (23456,'Kumar','Gombak','012-6101617','MLVK')
INSERT INTO student VALUES (34567,'Ridwan','Selayang',' ','DPG')
INSERT INTO student VALUES (45678,'Low Teck','Ampang','013-2356894','SSK')
INSERT INTO student VALUES (56789,'Aminah','Bangsar','017-25677','DPG')

CREATE TABLE course_table(
course VARCHAR(15),
subject1 VARCHAR(7),
subject2 VARCHAR(7),
subject3 VARCHAR(7),
lect1 VARCHAR(5),
lect2 VARCHAR(5),
lect3 VARCHAR(5))

INSERT INTO course_table VALUES ('DTM','TT235','TT695','PP563','L003','L322','L056')
INSERT INTO course_table VALUES ('MLVK','TT365','TT695','SS003','L123','L322','L601')
INSERT INTO course_table VALUES ('DPG','PP563','SS003','PP999','L056','L056','L003')
INSERT INTO course_table VALUES ('SSK','TT234','TT235','PP023','L123','L003','L322')

CREATE TABLE lecturer(
lect_id VARCHAR(5),
NAME VARCHAR(15),
address VARCHAR(10),
qualification VARCHAR(8),
department VARCHAR(20))

INSERT INTO lecturer VALUES ('L003','John','Damansara','Msc CS','Teknologi')
INSERT INTO lecturer VALUES ('L123','Milah','Kajang','Mba','Perdagangan')
INSERT INTO lecturer VALUES ('L056','Ahmad','Gombak','Bsc CS','Teknologi')
INSERT INTO lecturer VALUES ('L322','Raj','Kajang','Bsc IT','Teknologi')
INSERT INTO lecturer VALUES ('L601','Siti','Cheras','Ba Econ','Perdagangan')

so the requirement is to show a table of:
i) Aminah’s lecturer and subject
ii) Subjects taught by Ahmad

it's hard to show the relation of the tables and show in one output, at least i can say that for myself. for what it's worth, i just know how to use the commands up to normal 1 to 1 primary/foreign key. nothing more than that. so a little bit of coding and explanation from anyone better here would surely help.

Thanks in advance.
Maulord.

Options: ReplyQuote


Subject
Written By
Posted
Need help to construct basic query for 3 small tables
December 13, 2014 02:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.