Php 从第二个表中查询所有项
我有两张桌子Php 从第二个表中查询所有项,php,mysql,Php,Mysql,我有两张桌子 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
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下从表2中获取所有项目。另外,有些项目是用单键文本编写的,我不能使用查询从命令提示符中选择,因为我在我的表中只看到奇数字符。如果第二个表中有更多列,也可以使用
select*from table2,其中table2.table1\u id=table1.id
SELECT id, table1_id, item
FROM table2
WHERE table2.table1_id=table1.id