謝晒的PHP網頁設計
聯絡E-mail:
sean0704@gmail.com
站內搜尋
Wednesday, February 13, 2013
[MYSQL] 自我連結 (在同一份資料表中做聯結)
當 工號、姓名、主管工號 放在同一份資料表時,本範例可查詢出主管姓名。
SELECT boy1.name AS name1,boy2.name AS name2 FROM boy AS boy1 INNER JOIN boy AS boy2 ON boy1.boy_boss_id = boy2.id
說明:也就是雖然只有一個資料表,但我們把它當作兩個獨立的資料表去 join 就對了。
No comments:
Post a Comment
Newer Post
Older Post
Home
View mobile version
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment