我有一个包含以下字段的表 TBLCUTOMERS:
- cutomerid
- customername
- customerphone
我有另一个包含以下字段的表 TBLTRANSACTIONS:
- transactionid
- customerid (foreign key to table above)
- transactiondetail
- transactionamount
我有一个从 tbltransactions 获取所有交易的查询:
"select * from tbltransactions";
我怎么能在其中添加一个子查询,以便我从 TBLCUSTOMERS 中获取针对上述查询中每个 CUSTMERID 的 CUSTOMERNAME?
期望输出:
- transactionid
- customername (from tblcustomers)
- transactiondetail
- transactionamount
请注意,我是 MySql 的新手。谢谢
最佳答案
select tt.transactionid ,tc.customername,tt.transactiondetail,tt.transactionamount from tbltransactions tt,TBLCUTOMERS tc where tt.customerid=tc.cutomerid
我认为这将解决您的目的。供您引用检查link
关于mysql - 如何在 MYSQL 查询中添加子查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27614609/