MySQL database experiment three: Connection query

Source: Internet
Author: User

Experiment three connection query

Experiment Name: Connection query (2 hours)

First, the purpose of the experiment

Understand the operation and basic usage of join statement, master the concept and use of inner connection, outer connection, self-connection.

Second, the experimental environment

is a Chinese client for MS SQL SERVER 2005.

Iii. Examples of experiments

1. Check the status of each student and his/her elective courses

SELECT student.*,sc.*

From STUDENT,SC

WHERE Student.sno = SC. Sno;

2. Search for the student number of at least elective course number C2 and C4

SELECT x.s#

From SC as x,sc as Y

WHERE x.s# =y.s# and x.c# = ' C2 ' and y.c# = ' C4 ';

3. Retrieve the student number and name of at least one of the courses taught by Liu Teacher.

SELECT S.s#,sname

From S,sc,c,t

WHERE s.s#=sc.s# and SC. c#=c.c#

and c.t# =t.t# and tname = ' LIU ';

4. SELECT Student.sno,sname,ssex,sage,sdept,cno,grade

From Student left out JOIN SC on (STUDENT.SNO=SC. Sno);

5. For all students who have enrolled in the 2nd course and have scored above 90 points

SELECT Student.sno, Sname

From Student, SC

WHERE Student.sno = SC. Sno and/* CONNECTION predicate */

C.cno= ' 2 ' and SC. Grade > 90;/* Other qualifying conditions */

6. Query each student's number, name, elective course name and grade

SELECT Student.sno,sname,cname,grade

From Student,sc,course/* Multi-table connection */

WHERE Student.sno = SC. Sno

and SC. Cno = Course.cno;

Iv. contents and steps of the experiment

1. The search number is the course name and the teacher name of the S3 students.

2. Search for the name of the female student who has at least one of the courses taught by Liu Teacher.

3. Retrieve the course number of Wang students ' courses.

4. Retrieve the student number of at least two elective courses.

MySQL database experiment three: Connection query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.