Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sql-join 1 table: battle BattleShipStatus B1shipASunk B1shipBDamaged B2shipADamaged B2shipCOK table: ships CountryShip XshipA YshipB ZshipC XshipD Cross-Join.

Similar presentations


Presentation on theme: "Sql-join 1 table: battle BattleShipStatus B1shipASunk B1shipBDamaged B2shipADamaged B2shipCOK table: ships CountryShip XshipA YshipB ZshipC XshipD Cross-Join."— Presentation transcript:

1 sql-join 1 table: battle BattleShipStatus B1shipASunk B1shipBDamaged B2shipADamaged B2shipCOK table: ships CountryShip XshipA YshipB ZshipC XshipD Cross-Join 內部連接 select * from battle, ships; 4x4=16 rows select * from battle b, ships s where b.ship=s.ship; 4 rows BattleShipStatus B1shipASunk B1shipBDamaged B2shipADamaged B2shipCOK CountryShip XshipA YshipB ZshipC XshipD (a) (b) Inner-Join 交义連接

2 sql-join 2 BattleShipStatusCountryShip B1shipASunkXshipA B1shipBDamagedXshipA B2shipADamagedXshipA B2shipCOKXshipA B1shipASunkYshipB B1shipBDamagedYshipB B2shipADamagedYshipB B2shipCOKYshipB B1shipASunkZshipC B1shipBDamagedZshipC B2shipADamagedZshipC B2shipCOKZshipC B1shipASunkXshipD B1shipBDamagedXshipD B2shipADamagedXshipD B2shipCOKXshipD select * from battle, ships; 4x4=16 rows    

3 sql-join 3 select * from ships s, battle b where s.ship=b.ship; 4 rows BattleShipStatus B1shipASunk B1shipBDamaged B2shipADamaged B2shipCOK CountryShip XshipA YshipB ZshipC XshipD (c) Outer-Join 外連接 select * from ships s left join battle b on s.ship=b.ship; 5 rows Natural-Join 自然連接 table: battletable: ships XAB1AS XAB2AD YBB1BD ZCB2COk XD select * from ships s inner join battle b on s.ship=b.ship;

4 sql-join 4 select * from society where club=" 電腦 " and club=" 數學 "; select * from society a, society b where a.id=b.id and a.club=" 電腦 " and b.club=" 數學 "; 1 row idnameClub 001Ada 電腦 002Bill 電腦 003Cindy 數學 001Ada 數學 004David 英文 … (d) Self-Join 自我連接 Society idnameClub 001Ada 電腦 002Bill 電腦 003Cindy 數學 001Ada 數學 004David 英文 … 既是電腦學會會員, 同時又是數學學會會員。 select * from society where club=" 電腦 " and id=(select id from society where club=" 數學 ");

5 sql-join 5 http://www.appservnetwork.com/http://www.appservnetwork.com/ (AppServ 2.5.10) Reference: http://webdesign.kerthis.com/sql/sql_cross_joinhttp://webdesign.kerthis.com/sql/sql_cross_join ( 中文 ) http://www.1keydata.com/tw/sql/sql.htmlhttp://www.1keydata.com/tw/sql/sql.html ( 中文 ) http://www.ablmcc.edu.hk/~scy/1keydata/http://www.ablmcc.edu.hk/~scy/1keydata/ ( 中文 ) http://www.sqlguides.com/sql_basic.php http://www.sqlbook.com/SQL/ http://publib.boulder.ibm.com/iseries/v5r2/ic2928/info/sqlp/rbafymst02.htm#ToC http://programming.top54u.com/post/SQL-Inner-Join-Examples.aspx http://www.hiteshagrawal.com/mysql/understanding-mysql-joins


Download ppt "Sql-join 1 table: battle BattleShipStatus B1shipASunk B1shipBDamaged B2shipADamaged B2shipCOK table: ships CountryShip XshipA YshipB ZshipC XshipD Cross-Join."

Similar presentations


Ads by Google