Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**SQL HELP NEEDED** Hello I am having a problem with joins and was wondering if somone might be able to help out. For some reason

**SQL HELP NEEDED** Hello I am having a problem with joins and was wondering if somone might be able to help out. For some reason I keep getting an unkown error trying to use the W3 school ideas is there anything anyone could suggest to better do the below? I will need to do both a 2 table join and a 3.

The script for my starting base info is

/* use Find and Replace to replace all the ??? with your initials 'YourFirst' with your first name 'YourLast' with your last name 'x' with your Gender ('m' or 'f') (include the quotes) */ Drop database if exists Lab5CMW; Create database Lab5CMW; use Lab5CMW; create table students ( Studentid Int not null auto_increment, FirstName varchar( 30 ) not null, LastName varchar( 30 ) not null, Major varchar( 35) null Default 'Undeclared', AdmitDate DateTime null, GradDate DateTime null, Gender char(1) not null, DOB DateTime not null, constraint pk_Students primary key(StudentID) ); create table Courses ( CourseNumber Char(8) not null, CourseName varchar( 40 ) not null, Credits Decimal(2,1) not null, constraint pk_Courses primary key(CourseNumber) ); create table registration ( StudentID Int not null, CourseID char(8) not null, constraint pk_Reg primary key(StudentID, CourseID), constraint fk_Student foreign key(studentid) references students(studentid), constraint fk_courses foreign key(CourseID) references Courses(CourseNumber) ); -- add records to Courses Table Insert into Courses (CourseNumber, CourseName, Credits) values ('INFO1211','Access',2.0), ('INFO1311','Database Concepts', 3.0), ('INFO1511','Advanced Database Concepts',3.0), ('INFO1515','Database Administration', 3.0); -- add records to Students table insert into Students (FirstName, LastName, Major, AdmitDate, GradDate, Gender, DOB) values ('Don','Stark','CIT', '1970-10-04','1979-12-17','m','1939-02-13'), ('Debra Jo','Rupp','Nursing','1968-07-07','1972-12-18','f','1940-05-18'), ('Kurtwood','Smith','CIT','1962-09-15','1967-03-15','m','1935-12-02'), ('Mila','Kunis','broadcast media','1982-09-15',null,'f','1962-06-11'), ('Tanya','Roberts',default,'1973-07-07',null,'f','1941-10-04'), ('Tommy','Chong','pharmacy','1970-10-04','1979-12-17','m','1939-03-28'), ('Lisa Robin','Kelly','cosmotology','1978-03-28',null,'f','1958-10-07'), ('Josh','Meyers','undeclared','1978-10-07','1985-06-28','m','1961-01-05'), ('Danny','Masterson','political science','1981-01-05','1985-09-15','m','1960-04-17'), ('Ashton','Kutcher','criminal justice','1978-04-17','1978-12-19','m','1959-01-15'), ('Topher','Grace','primary education','1980-01-15','1985-06-28','m','1961-08-15'), ('Laura','Prepon','journalism','1980-01-1','1985-06-28','f','1961-11-21'), ('Wilmer','Valderrama','music','1980-01-15','1985-06-30','m','1960-03-17'), ('YourFirst','YourLast','CIT','2008-10-27',null,'x','1987-07-15'); -- add records to the Registration table insert into Registration (StudentID,CourseID) values (1,'INFO1211'), (1,'INFO1311'), (1,'INFO1511'), (2,'INFO1211'), (3,'INFO1211'), (3,'INFO1311'), (3,'INFO1515'); The assignment asks the following

16. (5 points) Write a query that displays the student firstname, lastname, course number, and course name for all students taking classes use an INNER Join. Label the output columns Student First, Student Last, Course Number, and Course Name. You should have 7 rows.

17. (5 points) Modify the query from the previous step to concatenate the student first and last name with a space between and sort the results by lastname, then by coursenumber (both ascending). Change the column names accordingly.

18. (5 points) Write the query to display the student first and last name, the course number and credit hours. Label the output columns First Name, Last Name, Course , and Credits. Use table aliases.

19. (10 points) Type and execute the command to display the student last name, and the total number of credits each student is registered for. Use appropriate column headings. You should have 3 rows.

20. (6 points) Modify the previous query to show all students, even if they have not registered for a class. You should have 14 rows. Students who are not registered will show NULL in the output.

Any help would be great Thank you in advance

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

d. What language(s) did they speak?

Answered: 1 week ago