从 2 个不同的表创建一个表 [英] Create a table from 2 different tables

查看:42
本文介绍了从 2 个不同的表创建一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下两个表:

  1. 包含 p_idname
  2. 列的产品
  3. 具有 u_idpassword 列的用户
  1. Products with columns p_id and name
  2. Users with columns u_id and password

我想创建一个名为 review 的第三个表,它将包含以下 3 列:p_idu_idreview.p_idu_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆