gpt4 book ai didi

php - 涉及4张表的查询,inner join?

转载 作者:行者123 更新时间:2023-11-29 03:35:19 26 4
gpt4 key购买 nike

我正在开发一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com