Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否可以使用一条查询语句_Php_Mysql - Fatal编程技术网

Php 是否可以使用一条查询语句

Php 是否可以使用一条查询语句,php,mysql,Php,Mysql,出于本示例的目的,我有两个表-夫妇表和人员表: Persons Table ID PERSON 1 Bob 2 Frank 3 Sally 4 Jane Couples Table ID HUSBAND WIFE 1 2 3 2 1 4 我是否可以编写一条查询语句,从两个表中进行选择,并使其以查询结果生成的方式进行连接: Couple 1 = Frank and Sally Couple 2 = Bob and Jane 谢谢 不过,请注意,现在并不是所有的婚姻都是夫妻关系。配偶1

出于本示例的目的,我有两个表-夫妇表和人员表:

Persons Table
ID PERSON
1 Bob
2 Frank
3 Sally
4 Jane

Couples Table
ID HUSBAND WIFE
1  2  3
2  1  4
我是否可以编写一条查询语句,从两个表中进行选择,并使其以查询结果生成的方式进行连接:

Couple 1 = Frank and Sally
Couple 2 = Bob and Jane
谢谢

不过,请注意,现在并不是所有的婚姻都是夫妻关系。配偶1和配偶2可能更能证明未来


不过,请注意,现在并不是所有的婚姻都是夫妻关系。配偶1和配偶2可能更能证明未来。

类似的事情

select m.id as husband_id, m.person as husband_name, f.id as wife_id, f.person as wife_name
from couples c
inner join persons m on m.id=c.husband
inner join persons f on f.id=c.wife

像这样的

select m.id as husband_id, m.person as husband_name, f.id as wife_id, f.person as wife_name
from couples c
inner join persons m on m.id=c.husband
inner join persons f on f.id=c.wife
SELECT 'Couple ' + c.id + ' ' + h.person + ' and ' + w.person
FROM Couples c
JOIN Persons h ON h.id = c.husband
JOIN Persons w ON w.id = c.wife