从 2 个不同的表创建一个表 [英] Create a table from 2 different tables
本文介绍了从 2 个不同的表创建一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下两个表:
- 包含
p_id
和name
列的产品 - 具有
u_id
和password
列的用户
- Products with columns
p_id
andname
- Users with columns
u_id
andpassword
我想创建一个名为 review 的第三个表,它将包含以下 3 列:p_id
、u_id
、review
.p_id
和 u_id
分别取自 products 和 users 表,并且会创建上述两个表的笛卡尔积,并添加第三列.我怎样才能做到这一点?
I want to create a 3rd table named review, which will have the following 3 columns: p_id
, u_id
, review
. The p_id
and u_id
are taken from products and users table respectively, and would kind of create a Cartesian product of the above two tables with added third column to it. How can I do that?
推荐答案
您可以使用 select 创建
You can create with select
create table3 (p_id int(1), u_id int(11), review varchar(64));
insert table3 select Products.p_id, Users.u_id, 'value_for_review'
from Products, Users
这篇关于从 2 个不同的表创建一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文