on ‎2018 Mar 30 9:34 AM
I have three tables Order,Customer,Address.
Can i know how to join three tables in flexible search to get below :
Customer name; E-mail address; Phone Number from address table; Country; Date of most recent order.
Any help would be appreciated?
Request clarification before answering.
SELECT * FROM
({{
SELECT {c.name}, {c.uid}, {c.pk} FROM {Customer as c}
}}) c
JOIN
({{
SELECT * FROM
({{
SELECT {o.creationtime}, {o.user}, {o.deliveryaddress} FROM {Order as o}
}}) o
INNER JOIN
({{
SELECT MAX({o.creationtime}) as mindate, {o.user} as minuser
FROM {Order as o}
GROUP BY {o.user}
}}) x ON o.createdts=x.mindate
}}) o
ON o.p_user = c.pk
JOIN
({{
SELECT {a.cellphone}, {a.country}, {a.pk} FROM {Address as a}
}}) a
ON o.p_deliveryaddress = a.pk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Below query should return data you need:
SELECT {c.name}, {c.uid}, {a.cellphone}, {a.country}, {o.creationtime} FROM {Customer as c}, {Address as a}, {Order as o} WHERE {c.pk} = {o.user} AND {o.deliveryaddress} = {a.pk} ORDER BY {o.creationtime} DESC LIMIT 1
Depending on your needs you might want to change o.creationtime to o.modifiedtime. You might also have to update fieldnames to match your custom modifications.
Best regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please check if you didn't misspelled (LIMT). Alternatively you can remove LIMIT 1 and use TOP 1:
SELECT TOP 1 {c.name}, {c.uid}, {a.cellphone}, {a.country}, {o.creationtime}
FROM {Customer as c}, {Address as a}, {Order as o}
WHERE {c.pk} = {o.user} AND {o.deliveryaddress} = {a.pk}
ORDER BY {o.creationtime} DESC
Regards,
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.