2011-10-27 77 views
3

是否有可能在MySQL中創建動態使用其他表中的表(動態使用其他表中的動作)(與在PHP中擴展類相同的想法)。例如:動態MySQL表

table1 
    table1_id 
    column1 
    column2 
    column3 

table2 
    table2_id 
    column4 
    column5 

所以,當我查詢表2我得到的所有列從表1

SELECT table1_id,column1,column2,column3,table2_id,column4,column5 FROM table2; 
+0

你只想對這個數據集執行選擇嗎?另外,每個表格中是否有與其他表格相關的列? – Nick

+1

http://dev.mysql.com/doc/refman/5.0/en/create-view.html您可能想要使用視圖 – Ignacio

+0

進行調查根據需要的「動態」方式,創建和銷燬視圖可能不會是值得的。 JOIN可能會更好。 – Nick

回答

8
CREATE VIEW t2_view AS <SELECT stuff FROM t1,t2> (not sure exactly how you want to join t1 and t2) 

SELECT * FROM t2_view; 

類似的東西是你在找什麼,我認爲。

+0

花了我一點時間瞭解什麼是一種觀點以及它是如何運作的,但我現在明白了,我喜歡這樣的感謝 – Tech4Wilco