我正在开发一个 PHP 应用程序,我需要一个涉及 4 个表的查询。表格是这样的:
news {news_pk, user, description, building_pk}
building {building_pk, area_pk, description}
area {area_pk,state_pk}
states {state_pk, name}
我想显示按州名过滤的结果(或者我认为相同的 state_pk
)。
我想显示某个州的新闻。
我不经常使用 MySQL,但在这个应用程序中我做了几个这样的查询,我不确定 inner join 是否是一个好的解决方案。
要仅显示特定州的新闻,哪个查询最有效?
最佳答案
您应该使用以下查询来连接表:
mysql_query("select a.news_pk,a.user.a.description,a.buiding_pk,b.building_pk,b.area_pk,b.description,c.area_pk,c.state_pk,d.state_pk,d.name from news as a,buiding as b,area as c,states as d where a.buiding_pk=b.building_pk and b.area_pk=c.area_pk and c.state_pk=d.state_pk");
关于php - 涉及4张表的查询,inner join?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22628687/