2012-02-05 105 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

相关问题