2017-04-12 32 views
0

我有三張表Order,Customer,Address。靈活的搜索或使用三個表的sql查詢?

我可以知道如何在靈活搜索中加入三張表以找出客戶訂單的地址(主要/默認地址或次要地址)嗎?

注意:主要地址是在客戶註冊期間創建的地址。

+0

請一些示例數據和預期產出增加的問題 – GurV

+0

你不應該使用直接的SQL查詢,總是在使用的hybris FlexibleSearch ! –

回答

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