如何加入两张桌子i

时间:2017-05-30 10:35:42

标签: mysql

我想完全加入两张桌子

productbill
BillID | TransactionID 
1      |  12344
2      |  34353

viewproduct
sno|BillID|Productname|Rate|Quantity|Amount
1  |1     |xyz        |12  |2       |24

required output
  BillID|TransactionID|Productname|Rate|Quantity|Amount
    1   | 12344       |xyz        |12  |2       |24 

我的查询是:

$joinview=mysql_query("select viewproduct.BillID,productbill.TransactionID,viewproduct.Productname,viewproduct.Rate,viewproduct.Quantity,viewproduct.Amount from viewproduct FULL OUTER JOIN  productbill ON productbill.BillID=viewproduct.BillID"); 

请帮助我

2 个答案:

答案 0 :(得分:0)

SQL内部联接是您所需要的!

SQL INNER JOIN

请参阅示例代码和演示数据库。

SELECT productbill.BillID, productbill.TransactionID, viewproduct.Productname, viewproduct.Rate, viewproduct.Quantity, viewproduct.Amount
FROM productbill
INNER JOIN viewproduct ON productbill.BillID = viewproduct.BillID;

答案 1 :(得分:0)

正如Maasoud所说,你需要内心加入。

查询将是

$joinview=mysql_query("SELECT productbill.billId as billId, productbill.TransactionID as TransactionID ,viewproduct.Productname as Productname, viewproduct.Rate as Rate, viewproduct.Quantity as Quantity, viewproduct.Amount as Amount FROM productbill AS productbill INNER JOIN viewproduct as viewproduct ON viewproduct.BillID = productbill.BillID");