我有三个表Order,Customer,Address。

我能知道如何在灵活的搜索中将三个表连接起来,以找出将客户定单交付到哪个地址(主要/默认地址或次要地址)吗?

注意:主要地址是在客户注册期间创建的地址。

最佳答案

你想要这样的东西吗?

select {order.deliveryAddress} from {Order as order},{Customer as customer} where {order.user}={customer.pk} and {customer.uid} = ?customerID


要么

select {address.pk} from {Order as order},{Customer as customer},{Address as address} where {order.deliveryAddress}={address.pk} and {order.user}={customer.pk} and {customer.uid} = ?customerID


要么

select {order:deliveryAddress} from {Order as order JOIN Customer as customer ON {order:user}={customer:pk}} where {customer:uid} = ?customerID

10-07 13:58