使用三个表灵活搜索或SQL查询?

时间:2017-04-12 09:23:51

标签: mysql sql hybris

我有三张表,订单,客户,地址。

我是否可以知道如何在灵活搜索中加入三个表格,以找出客户订单的送达地址(主要/默认地址或次要地址)?

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

1 个答案:

答案 0 :(得分:1)

你想要这样的东西吗?

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

OR

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

OR

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