[英]How to join two table with different fields to a single table in mysql?
I have two tables: 我有两个表:
ORDERS
OrderID CustomerID OrderDate
543 2 2015-09-18
621 37 2016-09-19
209 77 2016-09-20
CUSTOMERS
CustomerName Country
Alen Germany
Ana Mexico
Lisa India
I want to join both tables in a new table named CustomerOrders as following format: 我想按以下格式将两个表加入名为CustomerOrders的新表中:
OrderID CustomerID OrderDate CustomerName Country
543 2 2015-09-18 Alen Germany
621 37 2016-09-19 Ana Mexico
209 77 2016-09-20 Lisa India
How to list all records from two different tables to a new table? 如何列出从两个不同的表到一个新表的所有记录?
You known about database normalization? 您了解数据库规范化吗? You known about "first normal form", "second normal form"?
您知道“第一范式”,“第二范式”吗?
I don't explain it now. 我现在不解释。 All explained here: https://en.wikipedia.org/wiki/Database_normalization
全部在这里说明: https : //en.wikipedia.org/wiki/Database_normalization
假设您的客户表具有主键customer_id。
select o.order_id,c.customer_name,o.order_date, c.customer_id, c.country o.* from orders o left join customers c on o.customer_id=c.customer_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.