2012-02-05 114 views
0

所有的項目我有兩個表查詢從第二個表

CREATE TABLE table1 (id int primary key auto_increment,....); 
CREATE TABLE table2 (id int primary key auto_increment, 
        table1_id int foreign key references table1(id) on delete cascade, 
        item text not null,....); 

我想知道我怎樣才能從表1給出的ID表二的所有項目。另外一些項目是用Uniode文本編寫的,我不能使用查詢從命令提示符中選擇,因爲我只能看到我的表中有奇怪的字符。

回答

0
SELECT id, table1_id, item 
FROM table2 
WHERE table2.table1_id=table1.id 
+0

如果在第二個表中有更多的列,您也可以使用'SELECT * FROM table2 WHERE table2.table1_id = table1.id' – 2012-02-05 07:54:15

相關問題