- 情感問答
- 答案列表
三表關聯查詢: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)---更多請搜索:軟皇。