SQL exists is an existing judgment

Source: Internet
Author: User

SQL exists is an existence judgment. exists is an existence judgment. If there is a result in the following query, exists is true; otherwise, it is false. drop table Student; Drop table StudentExam; Drop table Exam; create table Student (StudentID int not null primary key, Name VARCHAR (50) not null) TYPE = InnoDB; create table StudentExam (StudentID int not null, ExamID int not null, Mark INT, IfPassed SMALLINT, Comments VARCHAR (255) TYPE = InnoDB; create table Exam (ExamID INT NOT NULL PRIMARY K EY, CourseID int not null, interval int not null, SustainedOn DATE, Comments VARCHAR (255), INDEX examcourse_index (CourseID), CONSTRAINT FK_ExamCourse foreign key (CourseID) REFERENCES Course (CourseID ), INDEX examprof_index (ProfessorID), CONSTRAINT FK_ExamProf foreign key (ProfessorID) REFERENCES descriptor sor (ProfessorID) TYPE = InnoDB; insert into Student (StudentID, Name) VALUES (1, 'Joe Wang '); INSE Rt into Student (StudentID, Name) VALUES (2, 'Henry al'); insert into Student (StudentID, Name) VALUES (3, 'amma zee '); insert into Student (StudentID, Name) VALUES (4, 'Lili Lil'); insert into Student (StudentID, Name) VALUES (5, 'Sam jun '); insert into Student (StudentID, Name) VALUES (6, 'dianna Wang '); insert into Exam (ExamID, CourseID, ProfessorID, SustainedOn, Comments) VALUES (1, 1, '2017-03-12 ', 'a difficult Test that shoshould last an hour '); insert into Exam (ExamID, CourseID, ProfessorID, SustainedOn, Comments) VALUES (2003, 1, '2017-03-13 ', 'A simple two hour test '); insert into Exam (ExamID, CourseID, ProfessorID, SustainedOn, Comments) VALUES (2003, 2, '2017-03-11 ', '1 hour long'); insert into Exam (ExamID, CourseID, ProfessorID, SustainedOn) VALUES (2003, 3, '2017-03-18 '); insert into Exam (ExamID, CourseID, professorID, Sus TainedOn, Comments) VALUES (2003, 2, '1970-03-19 ', '2 hours long'); insert into Exam (ExamID, CourseID, ProfessorID, SustainedOn) VALUES, 3, '2017-03-25 '); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (2003, 'satisfactory'); insert into StudentExam (StudentID, examID, Mark, IfPassed, Comments) VALUES (, 'good result'); insert into StudentExam (StudentID, ExamID, Mark, IfPasse D, Comments) VALUES (, 'scraped pass'); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (, 39,0, 'failed, and will need to retake this one later in the year '); insert into StudentExam (StudentID, ExamID, Mark, IfPassed) VALUES (,); insert into StudentExam (StudentID, examID, Mark, IfPassed, Comments) VALUES (3,4, 78,1, 'excellent result'); insert into StudentExam (Stud EntID, ExamID, Mark, IfPassed, Comments) VALUES (3,7, 82,1, 'Great result! '); Insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (4,8, 65,1, 'adequate performance'); insert into StudentExam (StudentID, ExamID, Mark, ifPassed, Comments) VALUES (, 'good result'); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES, 'Below exists'); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (5, 1, 26, 0, 'Very poor performance. recommend this student drop this module '); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (, 'good result '); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (5, 2, 62,1, 'good result'); insert into StudentExam (StudentID, ExamID, Mark, IfPassed, Comments) VALUES (6, 3, 'excellent work'); insert into StudentExam (StudentID, ExamID, Mark, IfPassed) VALUES (6, 6, 69, 1); insert into StudentExam (StudentID, ExamID, mark, IfPassed, Comments) VALUES (6,10, 58,1, 'adequate performance '); SELECT StudentID, Name FROM Student sWHERE EXISTS (SELECT StudentID FROM StudentExam e WHERE Mark <40 AND e. studentID = s. studentID );

Related Article

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.