SQL Server高级内容之子查询和表链接
1 Select 2 3 testID,stuID,testBase,testBeyond,testPro 4 5 from Score 6 7 where stuID=( 8 9 select stuID from Student where stuName=’Kencery’10 11 )
1 Select 2 3 testID,stuID,testBase,testBeyond,testPro 4 5 from Score 6 7 where stuID in( 8 9 select stuID from Student where stuName=’Kencery’10 11 )
1 use Test 2 3 go 4 5 create table testNum1 6 7 ( 8 9 Num1 int10 11 );12 13 create table testNum214 15 (16 17 Num2 int18 19 );20 21 insert into testNum1 values(1),(2),(3)22 23 insert into testNum2 values(4),(5)
1 Select s1.stuID, 2 3 s1.stuName, 4 5 s1.stuSex, 6 7 s2.testBase, 8 9 s2.testBeyond 10 11 from Student as s112 13 inner join Score as s214 15 on s1.stuID=s2.stuID16 17 where s1.stuIsDel=0;
1 create table tblMain 2 3 ( 4 5 ID int, 6 7 name nvarchar(20), 8 9 fid int10 11 );12 13 create table tblOther14 15 (16 17 ID int,18 19 name nvarchar(20)20 21 )22 23 insert into tblMain values(1,'张三',1),(2,'李四',2)24 25 insert into tblOther values(1,'C++'),(2,'.net'),(3,'java')26 27 select * from 28 29 tblMain as t130 31 inner join 32 33 tblOther as t234 35 on 36 37 t1.fid=t2.id
1 select * from 2 3 tblMain as t14 5 right join tblOther as t26 7 on t1.fid=t2.id