SQL sub-queries with JOIN of small scale chopper

//学生表
CREATE
TABLE student( ID INT PRIMARY KEY, s_name VARCHAR(16) NOT NULL, class_id INT NOT NULL); INSERT INTO student VALUES(1, "qf", 3), (2, "lap", 3), (3, "qfa", 8) //班级表 CREATE TABLE class( classID INT PRIMARY KEY , className VARCHAR ( 16 ) the NOT NULL ); the INSERT the INTO class the VALUES ( . 3 , "liaoshihua"), ( . 8 , "Changan Zip") // two lines following functions are similar: the former with JOIN, which sub-query
the SELECT S. ID, s.s_name, c.className the FROM Student S the LEFT the JOIN class C the ON s.class_id = c.classID the SELECT s.ID, s.s_name, ( the SELECT c.className the FROM class C the WHERE s.class_id = c.classID) className AS the FROM student s // here to use the AS statement after the results of a query, modify the query results.

 

Guess you like

Origin www.cnblogs.com/Stephen-Qin/p/11837472.html