Mysql加入多个表字段

时间:2013-10-17 20:55:53

标签: mysql database join

我再次碰到了一个我有问题的作业,是的,我一直在研究和阅读,所以这不是我第一次寻找答案。

赋值是从几个表中获取输出,这意味着需要“连接”,因为信息分散在不同的表中。

我创建了如下代码:

SELECT * FROM
order_, orderspec
WHERE order_.orderno = orderspec.orderno;

SELECT * FROM
order_, customer
WHERE order_.custno = customer.custno;

SELECT * FROM
order_, employee
WHERE order_.empno = employee.empno;

SELECT * FROM
orderspec, stock
WHERE orderspec.stockno = stock.stockno;

是否可以在一个查询/命令中完成所有这些操作?

1 个答案:

答案 0 :(得分:0)

您可以尝试这样: -

SELECT * FROM
order_, orderspec, customer, employee, stock
WHERE order_.orderno = orderspec.orderno
and order_.custno = customer.custno
and order_.empno = employee.empno
and orderspec.stockno = stock.stockno;