简体   繁体   English

如何从结构相同但不相关的两个表中选择数据? 的MySQL

[英]How can I select data from two tables with same structure but not related? MySQL

I'm new to MySQL and I'm working in a project where I have two tables (TABLE A and TABLE B), both tables have the same structure, same column names, etc but they are use for different tasks. 我是MySQL的新手,我在一个有两个表(表A和表B)的项目中工作,两个表具有相同的结构,相同的列名等,但是它们用于不同的任务。

But in some part of code is required to show info about the two tables and I think that if they have the same structure and column names why not use the same query to display the info? 但是在代码的某些部分中需要显示有关两个表的信息,我认为如果它们具有相同的结构和列名,为什么不使用相同的查询来显示信息?

I read something about INNER JOIN and CROSS JOIN but not sure if they are only to related table by foreign keys 我读了一些有关INNER JOINCROSS JOIN但不确定它们是否仅通过外键指向相关表

I would like to know too if is possible to have two queries like: 我也想知道是否可能有两个查询,例如:

SELECT * FROM table_A..

SELECT * FROM table_B..

and then combine the results in the function like mysqli_fetch_assoc 然后将结果合并到类似mysqli_fetch_assoc的函数中

Can you give me ideas how to achieve this or what to use? 您能给我一些想法如何实现这一目标或使用什么吗? thanks. 谢谢。

查看MySQL UNION语法

(SELECT * FROM table_A) UNION (SELECT * FROM table_B)

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

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