select * from student as s,guanliyuan as g,teacher as t
創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)江都,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
where s.ids = g.ids and s.ids = t.ids
條件可以根據(jù)你的需要來查詢。
select?表1.id,表1.s1,表1.s2,表1.s3,表1.s4,表2.t1,表2.t2,表2.t3,ifnull(表3.m1,0),ifnull(表3.m2,0),ifnull(表3.m3,0)?from?表1?left?join?表2?on?表1.id=表2.id?left?join?表3?on?表1.id=表3.id
合并就是通過join,需要哪個(gè)字段就用表名打點(diǎn)引出字段
如果a是唯一的話那就select table1.id,table2.id,table3.id from table1,table2,table3 where table1.a='12' and table1.a=table2.a and table2.a=table3.a;
或者如果對(duì)下你給數(shù)據(jù)相同的話,可以用union 連接 在用一個(gè)標(biāo)志位,區(qū)分三張表!
用create table as select .......,但索引不會(huì)復(fù)制。
mysql select * from table1;
+------+-------+
| id | name1 |
+------+-------+
| 1 | aaa |
| 1 | bbb |
+------+-------+
2 rows in set (0.00 sec)
mysql select * from table2;
+------+-------+
| id | name2 |
+------+-------+
| 2 | ccc |
| 2 | ddd |
+------+-------+
2 rows in set (0.00 sec)
mysql create table table3 AS (select a.id,a.name1,b.id as id2,b.name2 from table1 a join table2 b);
Query OK, 4 rows affected (0.10 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql select * from table3;
+------+-------+------+-------+
| id | name1 | id2 | name2 |
+------+-------+------+-------+
| 1 | aaa | 2 | ccc |
| 1 | bbb | 2 | ccc |
| 1 | aaa | 2 | ddd |
| 1 | bbb | 2 | ddd |
+------+-------+------+-------+
4 rows in set (0.00 sec)
數(shù)據(jù)庫(kù)多表關(guān)聯(lián),一般采用外鍵比較方便,也可以額外建一個(gè)連接表做多表關(guān)聯(lián)的連接,但這樣稍微有點(diǎn)兒復(fù)雜,這些是建表方面的關(guān)聯(lián)。查詢關(guān)聯(lián),可以采用多表查詢的方式關(guān)聯(lián)查詢,這點(diǎn)要求稍高點(diǎn)兒,但關(guān)聯(lián)后再操作單表時(shí),別的表不用受太大的影響,這點(diǎn)特好。