- 情感问答
- 答案列表
三表关联查询:mysql三表关联查询[朗读]
看你的表结构,应该是表1和表2通过size_id关联,表1和表3通过type_id关联查询的sql:select*from表1join表2on表1.size_id=表2.size_idjoin表3on表1.type_id=表3.type_id至于增删改,你最好还是一条一条来,不要关联来做。
表结构是不是这样的?select1ksid,'数学'catnameinto#temp1unionselect2,'语文'select1ksid,'001'stidinto#temp2unionselect1,'002'unionselect1,'003'unionselect
"selecttop5*fromuserswhereidnotin(selecttop1idfromusersorderbyid)orderbyid"。
比如有三张表,student,teacher,project:1.第一种方法:select*fromstudent,teacher,projectwherestudent.id=teacher.sidandstudent.id=project.sid;2.第二种:select*fromstudentinnerjointeacheronstudent.id=teacher.sidinnerjoinprojectonstudent.id=project.sid;
表1id1name1code1type1表2id2name2code2type2表3id1name3code3type3(表1、表2、表3id是主键)连接方式:selecta.id1fromid1ainnerjoinid2bona.id1=b.id1innerjoinid3conc.id1=b.id1子查询嵌套:select*fromid1cwherec.idin(selecta.id1fromid2ainnerjoinid3bona.id1=b.id1)---更多请搜索:软皇。