首页 / PHP / 在php中编写多个表的查询
在php中编写多个表的查询
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在php中编写多个表的查询,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2022字,纯文字阅读大概需要3分钟。
内容图文
![在php中编写多个表的查询](/upload/InfoBanner/zyjiaocheng/708/789be876f58041bf824145654809ea09.jpg)
我正在写我的作业的最后一个问题,但我现在仍然坚持下去.这个查询要求我从2个表而不是1个表中获取信息.我对如何从两个表中获取这些信息以及如何将它们放在一起感到困惑.以下是我要编写的查询的说明.
Find the name, independence year, and region of all countries where English is an official language.
Order results by region ascending and alphabetize the results within each region by country name.
(44 results)
以下是我将用于此查询的表
Table "lab2.country_language"
Column | Type | Modifiers
--------------+-----------------------+----------------------------------------
country_code | character(3) | not null default ''::bpchar
language | character varying(30) | not null default ''::character varying
is_official | boolean | not null default false
percentage | real | not null default 0::real
Indexes:
"country_language_pkey" PRIMARY KEY, btree (country_code, language)
Foreign-key constraints:
"country_language_country_code_fkey" FOREIGN KEY (country_code) REFERENCES country(country_code) ON DELETE CASCADE
=> \d country
Table "lab2.country"
Column | Type | Modifiers
-----------------+-----------------------+--------------------------------------
country_code | character(3) | not null default ''::bpchar
name | character varying(52) | not null default ''::character varying
continent | continent | not null
region | character varying(26) | not null default ''::character varying
surface_area | real | not null default 0::real
indep_year | smallint |
population | integer | not null default 0
life_expectancy | real |
解决方法:
如上面的注释中所提到的,在这种情况下,您必须执行SQL(内部)连接.所以你会有类似的东西:
SELECT name, indep_year, region
FROM lab2.country
JOIN lab2.country_language
ON lab2.country.country_code = lab2.country_language.country_code
WHERE …
内容总结
以上是互联网集市为您收集整理的在php中编写多个表的查询全部内容,希望文章能够帮你解决在php中编写多个表的查询所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。