简体   繁体   English

从多个表中选择Mysql?

[英]Select from multiple tables Mysql?

I have 3 tables :我有 3 张桌子:

Table A1 : ID|Name|Date|Id_person
Table B1 : ID|Name|Date|Id_person
Table C1 : ID|Name|Date|Id_person

I want a query like:我想要这样的查询:

select * from table A1 as a , table B1 as b , table C1 as c where a.Id_person=1 or b.Id_person=1 or c.Id_person=1

I get result only if id_person=1 in the 3 tables, And i get no result if just one the 3 table don't respect the condition.只有当 3 个表中的 id_person=1 时我才会得到结果,如果只有 3 个表中的一个不遵守条件,我就不会得到结果。

How to get result from the tables even if one of theme don't respect the condition (id_person=1).即使主题之一不遵守条件(id_person=1),如何从表格中获取结果。

你可以试试:

SELECT * FROM A1 WHERE Id_person=1 UNION SELECT * FROM A2 WHERE Id_person=1 UNION SELECT * FROM A3 WHERE Id_person=1

Try that :试试看:

select * from table A1 as a 
left join table B1 as b on a.Id_Person = b.Id_Person
left join table C1 as c on a.Id_Person = c.Id_Person

See this post : LEFT JOIN vs. LEFT OUTER JOIN in SQL Server请参阅此帖子: SQL Server 中的 LEFT JOIN 与 LEFT OUTER JOIN

You can try UNION:你可以试试联合:

SELECT * FROM A1 as a WHERE a.Id_person=1
UNION ALL
SELECT * FROM B1 as b WHERE b.Id_person=1
UNION ALL
SELECT * FROM C1 as c WHERE c.Id_person=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM