mysql連線查詢

2021-09-21 17:13:30 字數 672 閱讀 7404

以前查詢都是隨便查到結果就行了,因為發現每次查詢的數量都很少,當然現在也是。不過效率一直是程式設計師執著的追求,我就多了解下差距。

首先是多張表聯合,一張模板種類category,一張模板表template,一張櫥窗表shopwin,一張櫥窗型別表type

現在要查詢乙個櫥窗型別為1,即shopwin中type=1的模板資訊。模板資訊在template表中,裡面的每一條都是乙個模板的資訊。限制條件在shopwin表中,shopwin表中儲存的是template和type的對應關係。每一條都是乙個type和乙個template對應。

這樣,我需要連線category,template,shopwin三張表來查詢櫥窗型別為1的櫥窗所包含的所有模板的資訊。

1

select

模板資訊(t.category要替換成c.name)

2from

shopwin s,template t,category c

3where s.type=14

and s.template=

t.id

5and t.category=c.id

唯有不斷學習方能改變! --ryan miao

mysql連線查詢例項 MySQL連線查詢例項詳解

建立表suppliers create table suppliers s id int not null auto increment,s name char 50 not null,s city char 50 null,s zip char 10 null,s call char 50 not...

mysql連線查詢例項 MySQL連線查詢例項詳解

建立表suppliers create table suppliers s id int not null auto increment,s name char 50 not null,s city char 50 null,s zip char 10 null,s call char 50 not...

mysql連線查詢on MySQL連線查詢例項詳解

建立表suppliers create table suppliers s id int not null auto increment,s name char 50 not null,s city char 50 null,s zip char 10 null,s call char 50 not...