最近更新: 2006-01-20

SQL~~表格聯接 (join)

t106 是產品名稱表 (barcode, pname, sno),t107 (sno, sname, dno) 是小分類表,t108 是中分類表 (dno, dname, lno) , t109 是大分類表 (lno, lname) 。 檢視大、中、小分類暨品名列表的查詢方式。

聯結式一

select t109.lname, t108.dname, t107.sname, t106.pname, t106.barcode from t106
inner join t107 on t106.sno = t107.sno
inner join t108 on t107.dno = t108.dno
inner join t109 on t108.lno = t109.lno

聯結式二

select t109.lname, t108.dname, t107.sname, t106.pname, t106.barcode  from t106
inner join ( t107 
  inner join ( t108 
    inner join t109 
    on t108.lno = t109.lno) 
  on t107.dno = t108.dno)
on t106.sno = t107.sno
相關文章
樂多舊網址: http://blog.roodo.com/rocksaying/archives/1026832.html