【发布时间】:2015-11-24 12:09:43
【问题描述】:
我在连接两个表时遇到了困难。
我有桌子
Customer_table
---------------------------------------
| CustomerId(PK) | Firstname | Lastname |
---------------------------------------
CustomerInterest_table
----------------------------------------
| CustomerId(PK,FK) | InterestId(PK,FK) |
----------------------------------------
Interest_table
-------------------------------
| InterestId(PK) | InterestInfo |
-------------------------------
我要做的是选择每个客户,并将兴趣与桌上的 FK 参考加入。
最终我想获取一个结果,其中包含从客户表中获取的客户,以及从 CustomerInterest_table 中获取的客户兴趣。
我喜欢构建这样的对象
{
customerId : 'Id12345,
firstname : 'John',
lastname : 'Doe',
interests : [{interestId : 1, interestInfo : 'Apples'}]
}
我将如何获取和加入表格? 非常感谢任何帮助。
【问题讨论】:
标签: sql sql-server join many-to-many