我正在尝试创建 2 个表的 View 。
目前,我正在使用下面的行,效果很好,但我收到的信息太多,我需要更有选择性并选择列:
第一个表
wp_cart66_orders and i need to pull
bill_first_name_, bill_last_name
status=, new or shipped etc...
第二个表
wp_cart_66_order_items
description, quantity
我不确定是否需要创建 View 或仅使用此查询。
此外,如果是这种情况,我可能需要指出如何创建它的正确方向。
select wp_cart66_orders.*, wp_cart66_order_items.*
from wp_cart66_orders, wp_cart66_order_items
where wp_cart66_orders.id=wp_cart66_order_items.order_id
and wp_cart66_orders.status = 'new';
谢谢。
最佳答案
编写您的选择性列、明确的联接,并重新命名两个表中的公共(public)列名称。
create view OrderItemsVW
as
select wp_cart66_orders.bill_first_name as Bill_First_Name,
wp_cart66_orders.bill_last_name as Bill_Last_Name,
wp_cart66_orders.Description as OrdersDescription,
wp_cart66_order_items.Description as OrderItemsDescription
from wp_cart66_orders
inner join wp_cart66_order_items
on wp_cart66_orders.id=wp_cart66_order_items.order_id
where wp_cart66_orders.status = 'new';
关于MySQL 从 2 个不同的表和列创建 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15670093/